Reputation: 12693
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. Lily 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.
Upvotes: 14
Views: 34482
Reputation: 17969
This command (beware, it would rewrite history):
git rebase --onto commitHash^ commitHash
(@ouah's solution didn't work for me, and instead Lily's did, but his solution shouldn't be a comment, it should be an answer like this.)
Upvotes: 5
Reputation: 145899
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
.
Upvotes: 17