通常会发生本地分支在远程分支后面/前面并且git报告它:
$ git status
On branch develop
Your branch is ahead of 'origin/develop' by 3 commits.
(use "git push" to publish your local commits)
但是,有没有任何简单的方法可以通过确切的提交来识别这些?我的意思是,在上面的例子中,前面有3个提交哈希值。
谢谢!
答案 0 :(得分:1)
有几种方法可以做到这一点,但我会做git log --oneline origin/develop..develop
。这应输出类似
1234abc Commit message
abcd123 Some other commit message
1a2b3c4 And yet another message
origin/develop..develop
表示“develop
分支中不在origin/develop
分支中的所有提交”。可以把它想象为“从第一个分支开始到第二个分支的差异”。
如果你落后了,你可以这样做:git log --oneline develop..origin/develop
。
如果你真的只想要哈希,而不是--oneline
,你可以使用像--pretty="%h"
这样的东西。这将输出类似
1234abc
abcd123
1a2b3c4
您可以在the documentation的修订版中详细了解^
,..
和...
:
您可以将此视为一组操作。根据命令发出的命令 line形成一组可从其中任何一个访问的提交,以及 然后可以从前面的
^
给出的任何一个提交到达 从该集中减去。剩下的提交就是出来的 命令的输出。各种其他选项和路径参数都可以 被用来进一步限制结果。因此,以下命令:
$ git rev-list foo bar ^baz
表示“列出所有提交的内容 可以从
foo
或bar
到达,但不能从baz
“。特殊符号
<commit1>..<commit2>
可用作简写符号 为^'<commit1>' <commit2>
。例如,以下任何一种都可以 可以互换使用:$ git rev-list origin..HEAD $ git rev-list HEAD ^origin