Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取git中位于远程分支后面/前面的提交哈希值_Git - Fatal编程技术网

获取git中位于远程分支后面/前面的提交哈希值

获取git中位于远程分支后面/前面的提交哈希值,git,Git,通常情况下,本地分支位于远程分支的后面/前面,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个提交散列 谢谢 有几种方法可以做到这一点,但我会使用git log--onelin

通常情况下,本地分支位于远程分支的后面/前面,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个提交散列


谢谢

有几种方法可以做到这一点,但我会使用
git log--oneline origin/develope..develope
。这应该输出如下内容

1234abc Commit message
abcd123 Some other commit message
1a2b3c4 And yet another message
1234abc
abcd123
1a2b3c4
origin/develope..develope
表示“在
develope
分支中不在
origin/develope
分支中的所有提交”。把它想象成“从第一个分支开始到第二个分支的差异”

如果你落后了,你可以做相反的事情:
git log--oneline develope..origin/develope

如果您真的只需要散列,而不是
--oneline
,您可以使用类似
--pretty=“%h”
的内容。这将输出如下内容

1234abc Commit message
abcd123 Some other commit message
1a2b3c4 And yet another message
1234abc
abcd123
1a2b3c4
有关修订版中的
^
的更多信息,请访问:

您可以将其视为一个集合操作。根据命令提交 行构成一组可从其中任何一个访问的提交,以及 然后,可以从前面用
^
给出的任何提交中访问的提交是 从那一组中减去。其余的提交是在 命令的输出。可以使用其他各种选项和路径参数 用于进一步限制结果

因此,可以使用以下命令:

$ git rev-list foo bar ^baz
表示“列出所有已提交的提交” 可从
foo
bar
访问,但不能从
baz
访问

特殊符号
可用作简写 对于
^'
。例如,以下任何一项都可能 可以互换使用:

$ git rev-list origin..HEAD
$ git rev-list HEAD ^origin

您提到了
,但我将添加一条注释,说明这是获取两个集合的说明符,即它将r1..r2和r2..r1合并。一个缺点是不清楚哪些是第一组,哪些是第二组。