git 如何在pull之前检查local和github之间的差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6000919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check the differences between local and github before the pull
提问by shin
Before using pull, I want to check if there are any differences between my local and github master.
在使用 pull 之前,我想检查一下我的本地和 github master 之间是否有任何差异。
How can I do it?
我该怎么做?
回答by Mark Longair
git pull
is really equivalent to running git fetch
and then git merge
. The git fetch
updates your so-called "remote-tracking branches" - typically these are ones that look like origin/master
, github/experiment
, etc. that you see with git branch -r
. These are like a cache of the state of branches in the remote repository that are updated when you do git fetch
(or a successful git push
).
git pull
真的相当于跑了git fetch
然后git merge
。该git fetch
更新您所谓的“远程跟踪分支” -通常这些都是那些看起来像origin/master
,github/experiment
等你有看到git branch -r
。这些就像远程存储库中分支状态的缓存,当您执行git fetch
(或成功git push
)时更新。
So, suppose you've got a remote called origin
that refers to your GitHub repository, you would do:
因此,假设您有一个远程调用origin
指向您的 GitHub 存储库,您将执行以下操作:
git fetch origin
... and then do:
...然后做:
git diff master origin/master
... in order to see the difference between your master
, and the one on GitHub. If you're happy with those differences, you can merge them in with git merge origin/master
, assuming master
is your current branch.
...为了查看您的master
, 和 GitHub 上的区别。如果您对这些差异感到满意,则可以将它们与 合并git merge origin/master
,假设master
是您当前的分支。
Personally, I think that doing git fetch
and git merge
separately is generally a good idea.
就个人而言,我认为分开做git fetch
和git merge
分开通常是个好主意。
回答by braitsch
If you're not interested in the details that git diff
outputs you can just run git cherry
which will output a list of commits your remote tracking branch has ahead of your local branch.
如果您对git diff
输出的细节不感兴趣,您可以运行git cherry
它,它将输出您的远程跟踪分支在本地分支之前的提交列表。
For example:
例如:
git fetch origin
git cherry master origin/master
Will output something like :
将输出类似:
+ 2642039b1a4c4d4345a0d02f79ccc3690e19d9b1
+ a4870f9fbde61d2d657e97b72b61f46d1fd265a9
Indicates that there are two commits in my remote tracking branch that haven't been merged into my local branch.
表示我的远程跟踪分支中有两个提交尚未合并到我的本地分支中。
This also works the other way :
这也适用于其他方式:
git cherry origin/master master
Will show you a list of local commits that you haven't pushed to your remote repository yet.
将向您显示尚未推送到远程存储库的本地提交列表。
回答by peter pan gz
And another useful command to do this (after git fetch) is:
另一个有用的命令(在 git fetch 之后)是:
git log origin/master ^master
This shows the commits that are in origin/master but not in master. You can also do it in opposite when doing git pull, to check what commits will be submitted to remote.
这显示了在 origin/master 中但不在 master 中的提交。您也可以在执行 git pull 时反其道而行,以检查将提交到远程的提交。