I'm currently cleaning up my repo from old unused big files and random branches left hanging around. This has created some empty commits which I've been able to delete from git. However, I can't delete this empty merge commit. See attached image of my git tree. I have 2 branches other than main (branching off higher up in the git tree) called alex and pierre.
See attached image :
I've tried this git rebase command :
git rebase --onto 129294f9cda35e8c5861122668351519318fccec de782492dfa62b19d35a8c703a241a793475ff08
It gave me weird conflicts on the .gitignore file. After resolving that the rebase still failed and I was left with a very weird looking git tree with my pierre branch all on it's own. I had to run git rebase --abort
. I think the rebase is not working because of the two branches above which are currently like this :
I'm currently cleaning up my repo from old unused big files and random branches left hanging around. This has created some empty commits which I've been able to delete from git. However, I can't delete this empty merge commit. See attached image of my git tree. I have 2 branches other than main (branching off higher up in the git tree) called alex and pierre.
See attached image :
I've tried this git rebase command :
git rebase --onto 129294f9cda35e8c5861122668351519318fccec de782492dfa62b19d35a8c703a241a793475ff08
It gave me weird conflicts on the .gitignore file. After resolving that the rebase still failed and I was left with a very weird looking git tree with my pierre branch all on it's own. I had to run git rebase --abort
. I think the rebase is not working because of the two branches above which are currently like this :
1 Answer
Reset to default 1git filter-repo --prune-degenerate=always
should be able to get rid of such commits. (The tool is available from GitHub or pip.)
Alternatively, the manual approach:
- Edit the raw commit object with
git replace --edit <merge_commit>
, removing the unnecessary 2nd parent. This will create a 'replace' ref that makes Git tools pretend they see a different object than there is. - Verify that tools now see the wanted commit history.
- Bake for ~10 minutes using
git filter-branch
(without any specific options). This will rewrite the commit history to fully incorporate the "replacement" object.