Remove a lot of files in git filter-branch

女生的网名这么多〃 提交于 2019-12-21 09:14:16

问题


I'm migrating a repository from svn to git.

In this last step, I want to remove tons of files that aren't needed from the history.

I'm trying the following command:

git filter-branch --prune-empty --index-filter \
  "for file in $(cat files); do git rm -rf --cached --ignore-unmatch ${file}; done" -f

But it says that the argument list is too long.

I could rewrite this like:

for file in $(cat files); do
  git filter-branch --prune-empty --index-filter \
    "git rm -rf --cached --ignore-unmatch ${file}" -f
done

But it will run filter-branch tons of times, and the history is long.. so, it would take too much time.

Is there a faster way to filter-branch removing lots of files?


回答1:


I'd recommend using The BFG, a simpler, faster alternative to git-filter-branch specifically designed for removing unwanted files from Git history.

You mentioned in your comment that the problem files are generally big binaries, and The BFG has a specific option for handling this - you should carefully follow the BFG's usage instructions, but the core part is just this:

$ java -jar bfg.jar  --strip-blobs-bigger-than 10M  my-repo.git

Any files over 10MB in size (that aren't in your latest commit) will be removed from your Git repository's history. You can then use git gc to clean away the dead data:

$ git gc --prune=now --aggressive

The BFG is typically at least 10-720x faster than running git-filter-branch, and generally easier to use.

Full disclosure: I'm the author of the BFG Repo-Cleaner.



来源:https://stackoverflow.com/questions/17993505/remove-a-lot-of-files-in-git-filter-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!