git 问题 - 与分支分离
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5251492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git problem - got detached from branch
提问by Oded Harth
Accidently I got detached from my application branch:
不小心我从我的应用程序分支中分离出来:
Not currently on any branch. nothing to commit (working directory clean)
目前不在任何分支上。无需提交(工作目录干净)
How can I return to the branch?
我怎样才能回到分行?
回答by Mark Longair
Try:
尝试:
git checkout master
... or whatever branch you were previously on. To give some further explanation:
...或您以前所在的任何分支。做一些进一步的解释:
One of the most common uses of git checkout
is to switch from one branch to another. e.g. git checkout experiment
, git checkout master
. However, you can also give it the name of a tag, or the SHA1 sum (object name) of a commit - in those cases, git will change HEAD (which normally points to a branch, indicating that that's your current branch) to point to that tag or commit. This is known as "detached HEAD" or "not being on a branch" - the main difference is that if you create commits when you're in detached HEAD mode, they won't advance a branch, so they're easier to lose track of.
最常见的用途之一git checkout
是从一个分支切换到另一个分支。例如git checkout experiment
,git checkout master
。但是,你也可以给它一个标签的名称,或者提交的 SHA1 总和(对象名称)——在这些情况下,git 将把 HEAD(通常指向一个分支,表明这是你当前的分支)指向到那个标签或提交。这被称为“分离的 HEAD”或“不在分支上” - 主要区别在于,如果您在分离的 HEAD 模式下创建提交,它们不会推进分支,因此它们更容易丢失踪迹。
However, this is a very useful thing to be able to do when you want to look at the state of your repository at some random point in the past. (e.g. jumping around in this way is often the first step of trying to find the last good commit for (the awesome) git bisect
.)
但是,当您想查看过去某个随机点的存储库状态时,这是一件非常有用的事情。(例如,以这种方式跳来跳去通常是尝试为 (the awesome) 找到最后一个好的提交的第一步git bisect
。)
回答by Tomas
git checkout master
Or any other branch you want.
或者你想要的任何其他分支。