相关:List Git commits not pushed to the origin yet
git rev-parse HEAD
为我提供了工作区中的最新提交,但这可以是本地提交的 githash。换句话说,一个尚未推送到远程的提交
如何在工作区的远程中找到也存在的最新提交
最佳答案
要获取当前 checkout 分支的已配置远程分支的最新提交,请执行以下操作
# first get your remote-tracking branches up-to-date with remote
git fetch
# then do
git rev-parse @{upstream}
# or even just
git rev-parse @{u}
(注意:@{upstream}/@{u}
是不是占位符,它们应该按原样输入)
来自 doc :
[<branchname>]@{upstream}, e.g. master@{upstream}, @{u}
The suffix @{upstream} to a branchname (short form @{u}) refers to the branch that the branch specified by branchname is set to build on top of (configured with branch..remote and branch..merge). A missing branchname defaults to the current one.
关于Git找到第一个非本地提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68554761/