2

I'm converting a big SVN repository into multiple git repositories (one for each project).

I am running svn2git for each repo with all unwanted directories --excluded this works well to keep the tags and branches (I delete all the unrelated tags & branches after the conversion)

The only problem is I have loads of empty commits (commits relating to the excluded directories).

Is there any way to exclude these empty commits during the svn2git process?

This solution is a fine way to remove them after the fact, but filter-branch only affects the current branch, and not all the other branches and tags.

Community
  • 1
  • 1
William Denniss
  • 16,089
  • 7
  • 81
  • 124
  • 1
    you can use `git filter-branch … --all` to filter all branches and tags – knittl Aug 15 '11 at 15:41
  • you're right, I'll give that a try. I'm very interested to know if there is a way to do this in svn2git during that process though. Everything seems cleaner when you get it right the first time, rather than rewriting the history afterwards. – William Denniss Aug 15 '11 at 15:56

1 Answers1

10

Worked it out.

To the best of my knowledge, this command will rewrite the history, removing the blank commits, but preserving everything else.

git filter-branch --tag-name-filter cat --prune-empty -- --all

You can use this command to query the number of commits before and after as a quick test:

git log --pretty=format:'' | wc -l

William Denniss
  • 16,089
  • 7
  • 81
  • 124
  • This worked, but left an empty initial commit - any idea on how to also filter that? – mthomas Jul 20 '18 at 15:18
  • filter-branch works great, but `wc` has missed one commit. You should use `git rev-list --count @` to count commits. – marbel82 Oct 28 '19 at 11:21