Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a 'git commit' from LOG, like it had never existed

Tags:

git

I have made a mistake in one of the commits. Now I want to completely delete this commit, so it looks like it has never existed. I don't want to see this in log.

I have tried all tips from this question ("How to delete a 'git commit'"), but I can see the commit in the log. How I can completely delete it?

-- Edit --

Ok, I do not give the completely information. Kevin Ballard are correct.

By now, I do not push this commit, it's only in my machine. The ouah answer work, the command

git log

will not show, but what the command

git reset --hard HEAD^

do is "chekout last commit and change the the branch to this", so I continue seeing that commit with a graph program like SmartGit.

--Edit 2--

No, this is a SmartGit bug!!!! The commit really disappear. I have to close the windows of log and than open again. The commit is no more there.

like image 545
Rodrigo Avatar asked Jan 17 '12 20:01

Rodrigo


1 Answers

If it is the last commit

git reset --hard HEAD^

if it is not the last commit

git rebase -i commit_hash^

an editor will open, delete the whole line with the commit, save and quit.

Note that rewriting history or rebasing if the branch has already been pushed is usually a bad idea and you may prefer to use

git revert commit_hash

that will add a new commit that reverts the commit commit_hash.

like image 160
ouah Avatar answered Oct 06 '22 09:10

ouah