git 提交本地和远程之间的差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7057950/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:49:22  来源:igfitidea点击:

Commit differences between local and remote

git

提问by ack

How can I ask what commits are different between my current local branch and the remote repo that I push to?

我如何询问我当前的本地分支和我推送到的远程存储库之间的提交有何不同?

Not exactly a git diff origin/master master-- I don't want to see code differences. Just a list of changes like git log.

不完全是git diff origin/master master- 我不想看到代码差异。只是一个更改列表,例如git log.

I want to quickly see how long it's been since I pushed and how out of sync I am.

我想快速查看自推送以来已经过去了多长时间以及我有多不同步。

回答by Silfverstrom

git can not send this information remotely. You would have to do a git fetch(fetching the changes, without altering your working copy). You will then have a branch called "origin/master" which will enable you to use git log master..origin/master to get the variance between the two.

git 无法远程发送此信息。您必须执行 git fetch(获取更改,而不更改您的工作副本)。然后,您将拥有一个名为“origin/master”的分支,这将使您能够使用 git log master..origin/master 来获取两者之间的差异。

git fetch
git log master..origin/master

回答by Ben James

You can see which commits are on origin/masterbut not yet on masterusing

您可以看到哪些提交正在进行origin/master但尚未master使用

git log master..origin/master

To see which commits are on your masterwhich you haven't yet pushed, use

要查看您master尚未推送的提交,请使用

git log origin/master..master

回答by ct.kuo

git log HEAD..origin/yourproject --graph

git log HEAD..origin/yourproject --graph

回答by user3511585

With VS2015 and git version 2.7.1.windows.2, if you just type

使用 VS2015 和 git 版本 2.7.1.windows.2,如果你只是输入

git diff origin/master master

you will receive this:

您将收到:

fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree.

致命:模棱两可的参数“来源/主”:未知的修订版或路径不在工作树中。

To work around that, run

要解决这个问题,请运行

git branch -a

which will return something like

这将返回类似

  • master

    remotes/yourproject

  • 掌握

    遥控器/你的项目

Then use the entire remote path as git gives it to you, and it will work:

然后使用 git 给你的整个远程路径,它会工作:

git diff remotes/yourproject master