bash 获取最新远程提交的 SHA1

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

Get SHA1 of latest remote commit

gitbash

提问by miku

Possible Duplicate:
git bash : how to check if there's a new commit available

可能重复:
git bash:如何检查是否有新的提交可用

I am writing a script where I would like to compare the latest local commit to the latest upstream commit in order to tell the user there are commits to be pulled.

我正在编写一个脚本,我想将最新的本地提交与最新的上游提交进行比较,以便告诉用户有要提取的提交。

The latest local commit SHA is displayed with git log | head -n 1 | awk '{print $2}'.

最新的本地提交 SHA 显示为git log | head -n 1 | awk '{print $2}'.

Is there an equivalent for printing the SHA1 of the latest upstream commit?

是否有打印最新上游提交的 SHA1 的等价物?

回答by miku

Local head:

当地负责人:

$ git rev-parse HEAD

Remote head:

遥控头:

$ git ls-remote <url> <refs>

Displays references available in a remote repository along with the associated commit IDs.

显示远程存储库中可用的引用以及关联的提交 ID。

Example:

例子:

$ cd ~/github/scrapy/scrapy
$ git rev-parse HEAD
9f003a73daec59a73c23a2214b1b8d15a4391a2f
$ git ls-remote git://github.com/scrapy/scrapy.git HEAD
9f003a73daec59a73c23a2214b1b8d15a4391a2f

You can use diff to compare the output of the two:

您可以使用 diff 来比较两者的输出:

$ diff <(git ls-remote git://github.com/scrapy/scrapy.git HEAD) \
       <(git rev-parse HEAD)