Why did git install us (no branch)?

This morning we get out of our repo, and git sets us (no branch).

I do not understand this, why did this happen? And how to get out of this without losing our changes?

+68
git
Mar 23 '10 at 8:35
source share
3 answers

β€œCurrently there is no branch” means that you have a detached head , that is, your HEAD pointer directly refers to a commit instead of symbolically specifying the branch name.

You can get into this situation by checking the SHA1 commit, or when you are in the middle of a forwarding or when the merge fails. It's hard to say what you might have done to accidentally get into this situation.

It is said that you can lose your changes when you switch from a separate chapter to a branch, but the reflok will always track where your HEAD moves. In fact, Git 1.7.5 warns you when switching from a detached HEAD, it will lose commit. The only time you can really lose your job is when you have uncommitted changes that you might want to commit or block.

An easy way to find out what happened is git reflog or git log -g --decorate for a more detailed listing. The --decorate option will denote each SHA1 with the names of all branches that point to it. If the SHA1 of your current HEAD is exactly the same as that of the master, then you don't need to do anything other than git checkout master to get back on track. Otherwise, see If another branch is pointed at SHA1. If not, you might want to create a branch so that it hangs.

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

+87
Mar 23 '10 at 8:57
source share

It is hard to say without any details.

git pull pulls the changes from the remote repository and then merges. It can be configured to redirect instead of merging (either using git pull --rebase , or by setting the true value for branch.<branch_name>.rebase for the branch you are pulling into).

If you started on a branch, any merge type attraction will always leave you on that branch. On the other hand, the rebase command always works using a temporarily detached HEAD (otherwise called a "branch"). If you were left in this state during the attraction of the rebase type, then this is because part of the drag and drop during the collision encountered conflicts and expects you to resolve them and use rebase --continue (or --skip or --abort ).

By default, reflog stores every update that is made for HEAD (there can also be one for each branch). You can view reflog with git reflog show (or git log -g for a more detailed view). This can help you determine how you got into this condition.

If you are in the middle of rebase (you have a .git/rebase-apply directory), then it probably stopped to resolve some conflicts (conflicts). Use git status to check for "unrelated" entries. Any such entries must have conflict markers embedded in the files (provided that they are text files). You must edit them to resolve the conflict (s), and they mark them as merged by running git add on them. Then run git rebase --continue to continue reinstalling. You may encounter a large number of conflicts that should be handled in a similar way (edit, add, continue). If you decide that you no longer need a specific commit, you can skip it with git rebase --skip . You can abort all redirects with git rebase --abort . All of these redirection commands are listed in the error message when rebase terminates due to a conflict. After all pending commits have been applied (or skipped), your original branch will be updated with the last new commit, and your HEAD will be bound to it (if you interrupt, your HEAD will be reconnected without updating the branch).

If your disconnected HEAD was not caused by conflicts that occurred in the middle of the permutation, then your HEAD was disconnected at some point before pulling. You will need to evaluate the current state of the tree to decide what you want to do. You can use git show-branch --current --all or git log --graph --oneline --decorate --all or a graphical tool like gitk to find out how your current (separate) HEAD relates to your other branches . If you decide that you want to keep the contents of your HEAD, you can create a new branch for them using git branch new_branch_name . If you want to overwrite an existing branch, use git branch --force existing_branch_name . Then use git checkout branch_name to reconnect the HEAD of your repository to the branch again.

+31
Mar 23 '10 at 9:32
source share

Please note that if " git pull --rebase " was git pull --rebase when HEAD disabled, Git tried to find the detached HEAD upstream branch (which by definition does not exist) and emitted unnecessary error messages.

This is no longer the case with Git1.8.0.1 (November 26, 2012)

See this commit .

+1
Nov 26
source share



All Articles