1

I've committed some bad code a few days ago and today I changed and pushed an older head to master.

Before changing head:

commit 4

commit 3 - bad code starts here

commit 2 - i set the head here and pushed

commit 1

After changing head:

commit 2 - current head

commit 1

The problem is that now I want those 'bad commits' back.

It is possible to get them back?

2 Answers 2

1

You can use git reflog to solve your problem:

git reflog a8U3Ild... HEAD@{10}: commit 3 e3Noj1q... HEAD@{11}: commit 4 

Find the SHA-1 hashes of the commits which you deleted. The commit you want is the one for "commit 4" which was the head of the branch before you rolled things back. Then you can reset your current branch to "commit 4" like this:

git checkout master git reset --hard e3Noj1q 
Sign up to request clarification or add additional context in comments.

Comments

1

If your deleted commits are still referenced in the reflog you should be able to restore them as explained here :
http://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery#Data-Recovery

Man page of git reflog : http://git-scm.com/docs/git-reflog
Man page of git fsck : http://git-scm.com/docs/git-fsck

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.