2

Had to start version controlling a project not originally in version control. As a result the repo is now 17gb and needs to be paired down if we are going to get the repo up into github (the site itself is now paired down to about 600mb).

Basically we want to remove anything we have deleted in the process of pairing it down from the repo completely. I've found a great command to find every deleted file.

git log --all --pretty=format: --name-only --diff-filter=D | sort -u

Which lists the files beautifully.

Now how do I pipe this in to the command necessary to clear it from the history. Something along these lines.

git filter-branch --tree-filter 'rm -rf { file }' HEAD

I've made a backup copy of the repo so if I totally screw up things will be okay.

Is this the right command to loop all the files into? And if so how do I do this?

Nicholas Finch
  • 327
  • 1
  • 3
  • 11

1 Answers1

2

ok, xargs needs a little help. We need to use one per line, but substituted into that filter-branch command:

git log --all --pretty=format: --name-only --diff-filter=D | sort -u | while read -r line; do git filter-branch -f --tree-filter "rm -rf { $line }" HEAD; done

We also must specify the -f flag to filter-branch to remove the old refs, per Purging file from Git repo failed, unable to create new backup

Community
  • 1
  • 1
David Neiss
  • 8,161
  • 2
  • 20
  • 21
  • Help, I am getting an error message after passing through the first commit [code](WARNING: Ref 'refs/heads/master' is unchanged) Any clues? – Nicholas Finch Jun 12 '16 at 22:17
  • Never mind - I'm a SUDOer on this server - had to add another SUDO just before git filter-branch. Now seems to be working - thank you! – Nicholas Finch Jun 12 '16 at 22:31
  • Great that its working. If you could up vote this answer, that would give me some credit. Thanks. – David Neiss Jun 12 '16 at 22:39
  • Thank you @DavidN ! I panicked a little bit because every four commits altered it wanted me to enter in my sudo password again, which would've meant having to stay by the computer all night, but fortunately a sudo -s solved that problem. – Nicholas Finch Jun 12 '16 at 23:35