Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo a Mistake made while squashing the commits in GIT

Tags:

I wanted to squash my last 2 commits into one, so did a git rebase, in following way:

git rebase -i HEAD~2 

but due to a typo, what I actually ended up pushing into origin was:

git rebase -i HEAD-3 

Now, in the Github Pull Request it shows commit of some other unrelated commit. so basically, I want to remove commit 06674f0 which isn't mine, while keeping fcea5e0 in this PR.

how to fix the mess caused by simple typo?

like image 219
CuriousMind Avatar asked Apr 21 '12 15:04

CuriousMind


People also ask

Can you recover squashed commits?

Even when a commit is squashed , it's still recoverable as the data is in the commit history. Once you know the SHA of the blob you want to recover, use: $ git cat-file -p <SHA> > recover_file.

How do I undo an accidental commit?

In order to undo the last commit and discard all changes in the working directory and index, execute the “git reset” command with the “–hard” option and specify the commit before HEAD (“HEAD~1”).

How do I cancel squash?

To cancel your membership, login to your account, select the option to “Upgrade or renew your membership” and click the r red “X” under “My subscriptions.” You can also email: [email protected] or call 212-268-4090 for assistance.


1 Answers

Edit: Check your reflog with

git reflog 

Pick the commit previous to your first rebase and replace the x with appropriate number below:

Just undo your last rebase and redo it:

git reset --hard HEAD@{x} git rebase -i HEAD~2 .. git push -f origin master 

Remove your pull request and issue a new one.

like image 178
ralphtheninja Avatar answered Oct 09 '22 20:10

ralphtheninja