0

Sometimes I end up in following state, where the HEAD is not to be shown on the same commit as the master.

I suppose the HEAD must be checked out and following commits must go to HEAD. But how do I level both pointer on the same commit?

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Zveratko
  • 2,663
  • 6
  • 35
  • 64

2 Answers2

1

Sometimes I end up in following state, where the HEAD is not to be shown on the same commit as the master.

As mentioned in the comment above - read all about HEAD here.

To answer your questions:

Everytime you change your repository state your HEAD is modified and is updated and pointing to the current commit.

detached HEAD is when the HEAD is pointing to any commit other than the latest commit.

In the described link you can read all about it and there is a detailed explanation what is head which im not going describe here.


Can you explain me this?

I changed some file being on HEAD, then I have checkout master and did git svn rebase which failed as there was the file changed.

So I have reverted the changes and did git svn rebase still on master.
The result HEAD, master, git-svn are on the same commit.

I actually did nothing and it is fixed now? How is that?


Lets break it into pieces and ill explain each piece:

I changed some file being on HEAD

You can't do anything directly on HEAD. HEAD is simply a reference to commit. Its a simple text file which store the SHA-1 of the commit which your current branch is now pointing to.


then I have checkout master

Now your HEAD is pointing to the latest commit on master.


... did git svn rebase ... reverted the changes

Your HEAD is back to its original value before the rebase - no changes should appear. (don't confuse it with the git revert command)


The result HEAD, master, git-svn are on the same commit.
I actually did nothing and it is fixed now? How is that?

As explained above - look on it like this. You started to go on a walk (in this metaphor HEAD is storing how far you are from the point you started to walk). you walked here and there (your rebase that you tried to do ) and then you decided you don't like the walk and you went back home. (you reverted the rebase). Now HEAD is back in its original value since no "work" has been committed.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • The question is why the `git checkout master` and `git svn rebase` didn't align them on the first try? If I'm getting it correctly it should work right away. I often have this issue and I need to play with the IDE for a while to get it right. Maybe it is some rendering issue of Intellij IDE's git viewer. – Zveratko Apr 04 '16 at 07:59
  • Nope, first of all you need to understand what is a rebase. rebase change the history line of your branch. since you go back in time and re-write the commits again your HEAD is changed. Once you revert the change its aligned. – CodeWizard Apr 04 '16 at 08:38
0

Seems to me like you have a branch 'git-svn' which is 1 commit ahead of master and your HEAD is on that commit. You could just checkout the 'git-svn' branch and then push/merge it into master, if that is what you want?

niekname
  • 2,528
  • 1
  • 13
  • 27
  • I tried to cherry-pick the Revert "Removed.... commit. So I switched to master, git-svn rebase then I did the cherry-picking and after that I did dcommit. Some rebase should fix it then right? – Zveratko Apr 04 '16 at 07:01
  • Can you explain me this? I changed some file being on HEAD, then I have checkout master and did git svn rebase which failed as there was the file changed. So I have reverted the changes and did git svn rebase still on master. The result HEAD, master, git-svn are on the same commit. I actually did nothing and it is fixed now? How is that? – Zveratko Apr 04 '16 at 07:08