为什么git让我们(没有分支)? [英] Why did git set us on (no branch)?

查看:99
本文介绍了为什么git让我们(没有分支)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上我们从我们的回购中拉出来,并且git让我们(没有分支)。

我不明白,为什么会发生这种情况?如何在不丢失我们的变化的情况下摆脱它?

解决方案

目前不在任何分支上意味着您有一个分离式 head ,即您的HEAD指针直接引用提交而不是象征性地指向一个分支。

你可以通过检查SHA1的提交,或者当你处于rebase的中间,或者合并失败时进入这种情况。很难说出你可能做了什么来偶然发现这种情况。



据说,当你从一个分离的HEAD切换到某个分支时,你可能会失去你的改变,但reflog将始终跟踪您HEAD移动的位置。事实上,当从一个分离的HEAD切换时,Git 1.7.5会警告你失去提交。您唯一可以 失去工作的时间是您有未提交的更改,您可能想要提交或存储。



一种简单的方法查看发生了什么是 git reflog git log -g --decorate 以获得更详细的列表。 --decorate 选项会为每个SHA1标出所有指向它的分支的名称。如果您当前HEAD的SHA1与主控完全相同,那么除了 git checkout master 以外,您无需执行任何操作即可恢复正常。否则,请查看其他分支是否指向SHA1。如果不是的话,你可能希望创建一个分支来支持它。



另一个好的命令是 git branch -av ,它会同样列出所有分支和它们指向的内容,所以你可以看到你的(no branch)真的应该是什么。


This morning we pull from our repo, and git put us on (no branch).

I don't understand this, why did this happen? And how get out of it without losing our changes?

解决方案

"Not currently on any branch" means you have a detached head, i.e. your HEAD pointer is directly referencing a commit instead of symbolically pointing at the name of a branch.

You can get into this situation by checking out a commit by SHA1, or when you’re in the middle of a rebase, or when a merge fails. It’s hard to say what you may have done to get into this situation by accident.

It’s said that you may lose your changes when you switch from a detached HEAD to some branch, but the reflog will always keep track of where your HEAD moved. In fact, Git 1.7.5 will warn you when switching from a detached HEAD will lose commits. The only time you can really lose work is when you have uncommitted changes, which you may want to commit or stash.

A simple way to see what happened is git reflog or git log -g --decorate for a more verbose listing. The --decorate option will label every SHA1 with the names of all the branches that point at it. If the SHA1 of your current HEAD is exactly the same as master, then you don’t have to do anything but git checkout master to get back on track. Otherwise, see if the SHA1 is pointed to by some other branch. If not, you may wish to create a branch to hang on to it.

Another good command is git branch -av, which will similarly list all branches and what they point to, so you can see what your (no branch) is really supposed to be.

这篇关于为什么git让我们(没有分支)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆