[英]How do I get the commit ID of the branch tip in git?
一个 git 子模块目前在一个分支上,我不确定它是否在尖端。 如何获取分支提示的提交 ID,以便在必要时拉起子模块?
如果您在子模块中的分支foo
上,那么根据定义,您位于该分支的顶端。 也许您想要的是根据“超级模块”中提交的版本找出子模块应该提交的内容? 为此,您可以执行以下操作:
$ git rev-parse HEAD:mysubmodule
1b6577014983eb68c56025e6d3b95c8b9b7fc511
...然后将其与:
$ cd mysubmodule
$ git rev-parse HEAD
4dd9ac74b6dc1d0df8de5029656663bd879a4773
但是,您只需查看git status
的输出就可以更轻松地看到这一点:
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: mysubmodule (new commits)
“新提交”表示您的子模块落后于提交的版本,应该使用git submodule update mysubmodule
进行更新。
您还可以从git submodule
的输出中看到这一点,如果需要更新git submodule
,则与您的子模块对应的行将以+
开头。
您的问题的另一种解释是您的子模块位于分支foo
,但您想知道分支foo
的尖端在远程存储库中的位置。 为此,您可以执行以下操作:
$ cd mysubmodule
$ git fetch origin
$ git rev-parse origin/foo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.