Remove empty commits in git

后端 未结 2 781
鱼传尺愫
鱼传尺愫 2020-12-09 02:46

I just migrated a project from Mercurial to Git. Mercurial adds empty commits when you add tags, so I ended up with empty commits in Git that I would like to remove.

2条回答
  •  -上瘾入骨i
    2020-12-09 03:25

    Using --commit-filter should be faster than using --prune-empty

    $ git filter-branch --tag-name-filter cat --commit-filter 'git_commit_non_empty_tree "$@"' -- --all

    Then clean the backup refs as in torek's answer

    $ git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d

    Taken from here: Git - remove commits with empty changeset using filter-branch

提交回复
热议问题