2013-01-10 51 views
-1

Accidentaly我推送了一個包含本應被忽略的文件(node_modules和bower組件目錄)的提交。 由於我使用了很多依賴項,提交得到了相當大的數據,並且上傳了大量數據。從git回購記錄中刪除巨大的推送數據

我刪除這些文件在另一個承諾,其中包括一個.gitignore文件,但我會克隆應用程序的所有那些大文件下載爲歷史項目的每次。

有什麼辦法可以擺脫這種情況嗎?一種明確刪除的方法node_modules涼亭組件目錄從我的git回購?

+0

可能是http://stackoverflow.com/questions/2116778/reduce-git-repository-size的副本,http://stackoverflow.com/questions/5563564/remove-files-from-git-repo-completely ,http://stackoverflow.com/questions/872565/remove-sensitive-files-and-their-commits-from-git-history,或http://stackoverflow.com/questions/9854810/cleaning-up-git-歷史。 –

回答

1

你可以重寫git歷史並從git中刪除這些對象。 查找下一個環節上http://git-scm.com/book/ch6-4.html

+3

這個技巧:** git filter-branch --tree-filter'rm -f passwords.txt'HEAD **。我在書架上有這本書..我必須毫不猶豫地閱讀它:) – jviotti

0

我想說

git commit --amend 

git commit --rebase 

但是如果你想刪除的文件已經有相當長的一段時間,然後:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD 
0

即使您執行git rm,文件s將繼續在項目歷史上。這樣,您在克隆存儲庫時必須下載它們。要永久刪除文件,您需要更改歷史記錄。

如果添加文件的提交非常新,則可以在添加文件的提交之前執行git reset。但是,如果這些文件是前一段時間添加的,則需要使用git filter branch。當我想從存儲庫中刪除大文件時,我將展示一些我使用的步驟。

git filter-branch --index-filter 'git rm --cached --ignore-unmatch file-or-directory-that-you-want-to-remove-with-complete-path' --all. 

然後,您需要執行git push -f,因爲您更改了項目歷史記錄。這樣,當您再次克隆該項目時,被刪除的文件將不會再被下載。