0

I wanted to revert quite a lot of commits on my gitHub project: https://github.com/MarKco/workItOut

To do so I followed the instructions I found here: Why does git revert complain about a missing -m option? and How to revert Git repository to a previous commit?

I used a wide combination of resets, reverts and all. I must admit I didn't understand everything I was doing, I was on hurry and wanted this change (which looked fairly simple to me) to be done.

I managed to have in my working directory the old version, which sounds good. I committed and pushed, but what I see on the repo is strange:

* a2c09a3 (HEAD) Test
* 55fb272 Code optimization
* 3d26a26 Removed unused files which prevented compiling
* 6433aa5 Hopefully revert to f2c37d5
* ee730b5 Revert "Revert "Merge branch 'kevinoo-master'""
* 8fca74c Revert "Revert "Revert "Merge branch 'kevinoo-master'"""
* 2f64778 Revert "Removed proguard lines from build.gradle"
* 7349cc4 Removed proguard lines from build.gradle
* 85a4d64 Revert "Revert "Merge branch 'kevinoo-master'""
* b7b6328 Revert "Merge branch 'kevinoo-master'"
*   056df48 (origin/master, origin/HEAD, master) Merge branch 'kevinoo-master'
|\  
| * 30b9e79 (origin/kevinoo-master, kevinoo-master) Making it work again
| *   de5af76 Make it work again

I see two heads: the a2c09a3 (which is the one I want to be the real head, and it's the one I see in my working directory) and 056df48 which is labeled as "origin/master, origin/HEAD, master).

If I launch git status, I get

HEAD detached from 056df48
nothing to commit, working directory clean

and if I try to push, I get

Everything up-to-date

On github I don't see any commit after the 056df48.

So... I'm stuck :-/ How can I make the repository have a single head, and the head i want?

Thank you everybody

Community
  • 1
  • 1
Marco Zanetti
  • 4,051
  • 6
  • 32
  • 48

1 Answers1

1

you're in a detached head mode, git doesn't know what branch to push this commit to, you can easily tell it which branch explicitly

Assuming you want to push to master

git push origin HEAD:master

after that you can git checkout master

Another option would be merging this detached branch to your local tracking branch first

From your log the HEAD hash is a2c09a3 so

git checkout master
git merge a2c09a3
git push origin master
Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
  • Ah yes, you're right. I'll delete my earlier comment. – jub0bs Mar 22 '15 at 12:07
  • Thank you Mohammad, I merged the detached branch. What I don't get is: why was I still pointing at the branch? My head was already a2c09a3, or at least that's what I get from the graph. Also, I don't see a double line in my latest commits, so... why is there still a branch? Shouldn't it be already merged, if there's just one line? – Marco Zanetti Mar 22 '15 at 18:22
  • i don't understand, what tags do you get in the last commit in the git graph? – Mohammad AbuShady Mar 22 '15 at 18:31
  • hold on, ill clone your repo and check – Mohammad AbuShady Mar 22 '15 at 18:33
  • 1
    your repo looks fine, i don't understand the problem, could you explain more – Mohammad AbuShady Mar 22 '15 at 19:00
  • No double line because this is called a `fast forward` merge, since one commit was ahead of the other, with no divergence in their paths, git moves the commit pointer from the older commit to the newer commit, you can read more in the git doc http://www.git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging – Mohammad AbuShady Mar 22 '15 at 19:03
  • But... wasn't 056df48 already merging the branch with the master? Why did I need to merge again? – Marco Zanetti Mar 22 '15 at 19:41
  • you didn't, you merged the commits above `056df48`, those were in detached mode, which means they exist but there was no branch pointing at them, so we moved the master to point at it ( by doing the merge ) – Mohammad AbuShady Mar 22 '15 at 20:44