git history screwed up

1.4k views Asked by At

I was trying to do rebase to combine the commits into one single commit, but I ended up writing more commits and now its all screwed up big time.

Here is the tree: on running git status, I get

On branch master
Your branch is up to date with 'origin/master'.

Last commands done (5 commands done):
   pick 49147e5 squash
   pick 2c48387 Commit 
  (see more in file .git/rebase-merge/done)
Next commands to do (13 remaining commands):
   pick fddd4c7 commit 
   pick 5f01f80 commit 
  (use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'master' on '1550461'.
  (use "git commit --amend" to amend the current commit)
  (use "git rebase --continue" once you are satisfied with your changes)

nothing to commit, working tree clean

On running git log --oneline, I am getting:

Merge branch 'master' of .....
49147e5 squash
0310431 commit 4 which was PR
d4be53f commit 6
ea24a2d commit 5
1550461 commit 3
fc8115a commit 2
212138a commit 1
72d8fff Merge pull request #64 from branch 1
c5ad199 commit 14
2a6ceaf commit 13
6660dbf commit 12
b6c863e commit 11
88788e6 commit 10
5bbe8a7 commit 9
9731810 commit 8
1e4ac6b commit 7
ce3817c Merge branch 'master' of .... into branch 1
ec4c3e9 commit 6
5b8900b commit 5
d10eec9 commit 4 which was PR
5f01f80 commit 3
fddd4c7 commit 2
02ebbc8 Merge branch 'master' of ....into branch 1
3995cf2 pr changes v2
2c48387 commit 1

How I screwed up: From 72d8fff, I did git rebase -i HEAD~7 or 8, git pull, then git push. I wanted to squash all commits after d10eec9 into one single commit but I think I ended up writing on top of HEAD.

I was thinking to do git reset --hard 72d8fff then git push origin HEAD --force which will atleast bring me back to where I started.
Please save.

1

There are 1 answers

4
VonC On BEST ANSWER

bring me back to where I started.

Locally, you might have a look at git reflog, which will list the tips of branches and other references were updated in the local repository.

You will find there what HEAD refered to before your rebase.
If you reset --hard to that commit, you will be back to before the rebase.
You can also compare that commit with (if you have not done any other rebase) ORIG_HEAD and reset on that commit.

The idea remains: restore first locally your history, then squash again your last commits (this time, without rebase, but using git reset --soft), and force push once the state of your local repository is satisfactory.