Git - compare local and remote without fetching first?

后端 未结 1 1148
死守一世寂寞
死守一世寂寞 2021-02-09 05:45

I\'ve searched around and found no answer to this question.

I have an app running on Heroku. From my local machine I typically implement and just:

git a         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-09 06:45

    Although you can get some summary information about the branches in the origin repository using:

    git remote show origin
    

    ... you do need to fetch the branches from origin into your repository somehow in order to compare them. This is what git fetch does. When you run git fetch origin, it will by default only update the so-called "remote-tracking branches" such as origin/master. These just store where the corresponding branch was at in origin the last time you fetched. All your local branches that you've been working on are unaffected by the git fetch. So, it's safe to do:

    git fetch origin
    git log -p master..origin/master
    

    ... and then if you're happy with that, you can merge from or rebase onto origin/master.


    I would encourage you not to worry about the resources (either disk space or bandwidth) involved in the git fetch origin command. git efficiently sends just the objects that are necessary to complete the remote-tracking branches that are being updated, and unless you have unusually large files stored with your source code, this shouldn't make much of a difference. In addition, it's frequently useful to have the complete history of the branches from the other repository available even if you don't plan to use them, for example so you can examine that development history.

    0 讨论(0)
提交回复
热议问题