[英]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.