设置 OpenEmbedded 项目后,源将设置为分离头状态。您如何确定从哪个分支(本地或远程) check out 源代码?
是的,您可以检查分支并比较代码。有没有更简单的方法?
我使用的是 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
最佳答案
方案一: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:查找包含当前提交的所有分支
查找包含您当前已 checkout 的提交的所有分支(本地和远程跟踪分支):
git branch --all --contains HEAD
然后只检查每个分支的第一个提交,看看给定的提交是否是该分支的头:
git log -1 <branch>
关于git - 在 Git 中查找 HEAD 从哪个分支分离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18667578/