2013-01-10 52 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,因为您更改了项目历史记录。这样,当您再次克隆该项目时,被删除的文件将不会再被下载。