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

git - How to reduce the size of a repo on Github

I accidentally committed some large test wav files into my repository and they are using up a lot of space on my Github account. How can I remove these files from the history?

Note: these files were committed some time ago and are not on the HEAD commit.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

There's no way to remove them without modifying the history, so if anyone's pulled the changes, you may have to deal with that mess - see recovering from upstream rebase in man git-rebase. This can be pretty bad, depending on your workflow - one way or another you'll probably have to make everyone aware that they need to switch to the "new" master branch, rebasing any work in progress on top of it.

If the commit were still on the tip, you could reset to the commit before it:

git reset --hard HEAD^

or amend it:

git rm test.wav
git commit --amend

But since it's no longer at the tip, your best bet is probably to probably do it with an interactive rebase:

git rebase -i <commit-before-mistake>

Change "pick" to "edit" on the commit you want to fix, then have at it! (or even remove the whole commit if that's okay)*

After you finish doing whichever of these you pick, you'll have to force the push, since it's no longer a fast-forward:

git push -f origin

* If you've subsequently committed modifications to these files, you'll get issues as you continue on in the rebase. They should be straightforward to deal with, since you just want the files gone. Of course, if there've been a hundred commits since then that'll all cause conflicts, you could have a look at git-filter-branch. The relevant example from the man page is:

git filter-branch --index-filter ’git rm --cached --ignore-unmatch filename’ HEAD


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

...