I have a merge commit on a Git repository that I want to delete.
How to really delete a commit from git?
I mean DELETE a commit that has no commits after it. I just do not want it clogging the history (and occuping disk space).
Please do not answer with anything like "git -i rebase" as you can not use rebase to delete a commit with no child commits.
0 <-this is now HEAD and master
|
| this is a different merge between the same branches, master and hotfix-1
| /
0 0 <-THIS is the commit I want to DELETE (incorrect merge)
|\ /|
| X |
|/ \|
0 0
| |
| |
| |
| 0
| |
| |
| |
0 0 <- this is start of branch hotfix-1
| /
| /
|/
0
|
EDIT:
Please do not answer with anything like "git reset --hard HEAD~1" as that does not delete the commit for merge commits:
user@host /dir/subdir (master)
$ git checkout b605a0dd5e12e65081a2d8ffe7c905617b210605
Note: checking out 'b605a0dd5e12e65081a2d8ffe7c905617b210605'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at b605a0d... Merge branch 'hotfix-1'
user@host /dir/subdir ((b605a0d...))
$ git reset --hard HEAD~1 ## TRYING TO DELETE COMMIT
HEAD is now at 65e8158 Some commit message
user@host /dir/subdir ((Some tag))
$ git checkout b605a0dd5e12e65081a2d8ffe7c905617b210605
Previous HEAD position was 65e8158... Some commit message
HEAD is now at b605a0d... Merge branch 'hotfix-1'
user@host /dir/subdir ((b605a0d...)) ## COMMIT STILL THERE
$