获取SHA1最新的远程提交 [英] Get SHA1 of latest remote commit
问题描述
可能重复:
git bash:如何检查是否有新的提交可用
Possible Duplicate:
git bash : how to check if there’s a new commit available
我正在编写一个脚本,在该脚本中,我想将最新的本地提交与最新的上游提交进行比较,以告诉用户有待提交的提交.
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.
最新的本地提交SHA显示为git log | head -n 1 | awk '{print $2}'
.
The latest local commit SHA is displayed with git log | head -n 1 | awk '{print $2}'
.
是否有等效功能可打印最新的上游提交的SHA1?
Is there an equivalent for printing the SHA1 of the latest upstream commit?
推荐答案
本地标题:
$ git rev-parse HEAD
远程头:
$ git ls-remote <url> <refs>
显示远程存储库中可用的引用以及关联的提交ID.
Displays references available in a remote repository along with the associated commit IDs.
示例:
$ cd ~/github/scrapy/scrapy
$ git rev-parse HEAD
9f003a73daec59a73c23a2214b1b8d15a4391a2f
$ git ls-remote git://github.com/scrapy/scrapy.git HEAD
9f003a73daec59a73c23a2214b1b8d15a4391a2f
您可以使用diff比较两者的输出:
You can use diff to compare the output of the two:
$ diff <(git ls-remote git://github.com/scrapy/scrapy.git HEAD) \
<(git rev-parse HEAD)
这篇关于获取SHA1最新的远程提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!