Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this series of git-svn commands result in a detached HEAD?

Tags:

git

git-svn

I do this:

$ git svn clone http://monsterdebugger.googlecode.com/svn/ -s --prefix=svn/ monsterdebugger
$ cd monsterdebugger
$ git branch -a
* master
  remotes/svn/trunk
$ git co remotes/svn/trunk
Note: checking out 'remotes/svn/trunk'.

You are in 'detached HEAD' state. <And so on...>

I guess I'm not fully understanding what's going on under the hood here. Shouldn't remotes/svn/trunk be a tracking branch against the svn repo? Why did I end up with a detached head?

like image 789
Tim Keating Avatar asked Jan 04 '12 22:01

Tim Keating


People also ask

Why is git head detached?

When you use the git checkout command to view a commit, you'll enter “detached HEAD state”. This refers to when you are viewing a commit that is not the most recent commit in a repository. Detached HEAD state is not an error nor is it a problem. When you are ready, you can navigate back to the HEAD in your repository.

How do I fix a detached head in git?

If you want to keep changes made with a detached HEAD, just create a new branch and switch to it. You can create it right after arriving at a detached HEAD or after creating one or more commits. The result is the same. The only restriction is that you should do it before returning to your normal branch.

How do you reattach a detached head?

You must understand that any of your branches will not be affected if you ever get into a detached state . Now, the best way to reattach the HEAD is to create a new branch. We can do it as simple as git checkout -b <branch-name> . This will commit the changes from your temporary branch into the branch you need them.

What is a detached commit in git?

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. This detached head state occurs when a specific commit is checked out instead of a branch.


1 Answers

It's because it's a remote branch. You need to create a local branch for it, with something like:

git checkout -b my-trunk remotes/svn/trunk
like image 110
Karl Bielefeldt Avatar answered Sep 28 '22 09:09

Karl Bielefeldt