繁体   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