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
641 views
in Technique[技术] by (71.8m points)

github - Completely remove a file from whole git repository

Using git for a project, I accidentally added to a commit a big .zip file. I didn't notice until I started uploading it to github. When I noticed, I hit ctrl-c, git remove, git commit and uploaded it again (now with the file untracked).

I know that this wasn't the right choice to do, because once I committed the .zip, it stays in the repo until I revert the commit, but sadly I didn't.

Now, when someone tries to download from the repo, it takes a lot of time to do it, sometimes yields git the remote end hung up unexpectedly (which I've read can be solved by doing some git config) and is very annoying.

My point is: is there a way to tell further pull/fetch request that forget this specific file in this specific commit version?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Github provide a useful help page on removing files like this. There are also other questions on StackOverflow which cover this

See also this section of the Pro Git book, an example given there:

To remove a file named passwords.txt from your entire history, you can use the --tree-filter option to filter-branch:

$ git filter-branch --tree-filter 'rm -f passwords.txt' HEAD
Rewrite 6b9b3cf04e7c5686a9cb838c3f36a8cb6a0fc2bd (21/21)
Ref 'refs/heads/master' was rewritten

After the cleanup, you could also try a git gc to further compress and clean up for repository.


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

...