最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

git - How to delete empty merge commit - Stack Overflow

programmeradmin4浏览0评论

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 :

Share Improve this question edited Mar 10 at 11:48 Guildenstern 3,9622 gold badges28 silver badges54 bronze badges asked Mar 9 at 17:29 Pierre GueguenPierre Gueguen 91 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

git 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:

  1. 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.
  2. Verify that tools now see the wanted commit history.
  3. Bake for ~10 minutes using git filter-branch (without any specific options). This will rewrite the commit history to fully incorporate the "replacement" object.
发布评论

评论列表(0)

  1. 暂无评论