Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
838 views
in Technique[技术] by (71.8m points)

git rewrite history - remove filenames from specific path?

I've been playing around with the BFG Repo-Cleaner tool in order to clean up the history of a git repo by removing (temporary / large) files from several places in the directory hierarcy...

i.e. /root/test/a.txt /root/test2/a.txt

Now i'd like to remove all references of the 'test/a.txt' but keep the /test2/a.txt version..

Is there any way to cleanly remove that using BFG? (as mentioned on https://help.github.com/articles/remove-sensitive-data)

Since the repo has a fairly large history ( 10K commits ) BFG really is alot faster than the other methods i've seen so far...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm the developer of The BFG, and I'm glad you've been finding it useful and fast. Part of the special-sauce that makes the BFG so fast is that it's path-independent - so you can't say directly say something like --delete /root/test/a.txt. Adding some support for path-dependent action is something I'm thinking about, but I don't want it to adversely affect performance.

The key question when cleaning your repo is: What are you trying to achieve, out of these two options:

  • Reduction in Git repository size
  • Removal of private data

From your question, it sounds like your only aim is the first one, to reduce Git repository size. If /root/test/a.txt is fairly small- ie comparable in size to the rest of the legitimate files in your repository - you can't really use --strip-blobs-bigger-than X to get rid of it, as it would remove too many of your other regular files. But if that is the case, I would just relax, and let it go - it's not costing you much storage space compared to the entirety of your repo.

If /root/test/a.txt is big enough to bother you, you can probably just use --strip-blobs-bigger-than X to get rid of it - remember that The BFG protects all files in your current commit (or even more branches if you use --protect-blobs-from <refs>) - so legitimate big files that you're currently using won't get touched.

If you really want to get rid of this poor innocuous file, but don't want to filter on size, there are two BFG-supported options:

Use --delete-folders test

...which will delete the entire folder /root/test/ (and all other folders called 'test'), but not /root/test2/. Not much use if there are other things in /root/test/ that you want to keep.

Use --strip-blobs-with-ids <blob-ids-file>

...you have to look up all the Git blob-ids there have ever been for /root/test/a.txt, which you can do with a some git commands like this:

git log --format=%H -- /root/test/a.txt | xargs -IcommitId git rev-parse commitId:/root/test/a.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...