Bipario
Bipario

Reputation: 221

How to remove a commit?

I merged some commits in Git and now I need to delete this commit as it has some confidential information. I need to put the HEAD in the commit before the merge.

Upvotes: 0

Views: 94

Answers (2)

Gabriel Gartz
Gabriel Gartz

Reputation: 2870

There are another way to do this, but I have a solution in this case.

Let's suppose you are using master branch.

First I checkout the commit I want to be the last in master and recreate the master branch.

git checkout 2fa59698256c4c3fb85c6e32741071797d5965b3
git checkout -b master

Then I pull back forcing the server to remove it history.

git checkout --amend
git push origin master --force

This will erase all commits after.

You can use git rebalse~x then do the push with force... But When I'm in trouble I always remember to use the checkout, that I do all the time to switch between branch's.

Upvotes: 0

Zombo
Zombo

Reputation: 1

I prefer to use git rebase for this job, because a nice list pops up where I can choose the commits to get rid of. Choose how many commits you want to list, then invoke like this

git rebase -i HEAD~3

Sample list

pick aa28ba7 Sanity check for RtmpSrv port
pick c26c541 RtmpSrv version option
pick 58d6909 Better URL decoding support

Then git will remove commits for any line that you remove.

Upvotes: 1

Related Questions