簡體   English   中英

在Git中查找HEAD分離的分支

[英]Find which branch HEAD was detached from in Git

設置OpenEmbedded項目后,源將設置為分離頭狀態。 如何確定從哪個分支(本地或遠程)檢出源代碼?

是的,您可以查看分支並比較代碼。 有更簡單的方法嗎?

我正在使用Git 1.7.1版。

$ git config -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=git://arago-project.org/git/projects/meta-arago-amsdk.git
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.amsdk-06.00.00.00-integration.remote=origin
branch.amsdk-06.00.00.00-integration.merge=refs/heads/amsdk-06.00.00.00-integration

$ git branch -a
* (no branch)
  amsdk-06.00.00.00-integration
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/amsdk-05.06.00.00-integration
  remotes/origin/amsdk-05.07.00.00-integration
  remotes/origin/amsdk-05.08.00.00-integration
  remotes/origin/amsdk-06.00.00.00-integration
  remotes/origin/master
  remotes/origin/master-upstream

解決方案1:git reflog

如果你沒有移動你的HEAD引用,因為你的工作副本進入了分離頭狀態,你可以使用git reflog -1來找到你的頭被分離的位置:

git reflog -1
d761f4a HEAD@{0}: checkout: moving from feature to head~5

請注意,我不確定這些信息是否在舊版本的Git中可用。

即使你一直在移動你的HEAD引用,你仍然可以找到你在reflog中某處分離的點:

git reflog | grep checkout

對於無權訪問grep ,可以在PowerShell中使用findstr ,或者使用Git中內置的這些標志:

git log --walk-reflogs --grep-reflog "checkout" --oneline

解決方案2:查找包含當前提交的所有分支

查找包含您當前已簽出的提交的所有分支(本地和遠程跟蹤分支):

git branch --all --contains HEAD

然后只檢查每個分支的第一次提交,看看給定的提交是否是該分支的頭部:

git log -1 <branch>

感謝torek提供的簡化解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM