Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Undoing rewrite of history?

Tags:

git

rebase

I have a problem with the following situation:

  • several commits are pushed to a remote (our codereview system)
  • developer has rewritten history (edited some commit during a rebase) locally
  • when attempting to push again, codereview does not accept it (as this change can already haved passed review)

How can I 'reset' a -single- commit to what is in this remote?

The modified commit is not always HEAD, so I cannot simply do 'git reset --hard HEAD^ && git pull'.

edit:

Preferably the diff between the two versions are created as a new commit, but it is not really a necessity.

like image 833
Daniel Sloof Avatar asked Mar 20 '12 12:03

Daniel Sloof


People also ask

Does git revert rewrite history?

Reverting has two important advantages over resetting. First, it doesn't change the project history, which makes it a “safe” operation for commits that have already been published to a shared repository.


1 Answers

Check the reflog with:

git reflog

Then pick the HEAD that corresponds to the commit of your choice, e.g.

git reset --hard HEAD@{5}

would reset your branch to the point HEAD pointed at five commits ago.

like image 72
ralphtheninja Avatar answered Oct 12 '22 22:10

ralphtheninja