2014-01-16 68 views
58

如何放弃所有尚未推送的git提交,然后强制git不提交数据/目录中的任何内容?无法从git commit中删除文件

我试图强制覆盖从我的c9.io项目存储在github上的项目的所有更改。我不小心加入了一些mongodb数据文件。我试图将数据/目录添加到.gitignore。我从github中获取更新的.gitignore,但是当我尝试和git push时,data /中的这些顽固文件仍然处于提交状态。我也试过git reset,git rebase,git clean和this,我把dmpfile.sql改成了pi/data/node-login.1。

请帮我已经在这几个小时,我真的很沮丧

Counting objects: 15, done. 
Delta compression using up to 2 threads. 
Compressing objects: 100% (13/13), done. 
Writing objects: 100% (13/13), 150.22 KiB | 92 KiB/s, done. 
Total 13 (delta 6), reused 0 (delta 0) 
remote: warning: File pi/data/local.0 is 64.00 MB; this is larger than GitHub's recommended maximum file size of 50 MB 
remote: warning: File pi/data/node-login.0 is 64.00 MB; this is larger than GitHub's recommended maximum file size of 50 MB 
remote: error: GH001: Large files detected. 
remote: error: Trace: e6ade98208c08b634ed28aefea36dfbb 
remote: error: See http://git.io/iEPt8g for more information. 
remote: error: File pi/data/node-login.1 is 128.00 MB; this exceeds GitHub's file size limit of 100 MB 
To [email protected]:bobbyg603/goddard.git 
! [remote rejected] master -> master (pre-receive hook declined) 
error: failed to push some refs to '[email protected]:bobbyg603/goddard.git' 

的.gitignore:

lib-cov 
*.seed 
*.log 
*.csv 
*.dat 
*.out 
*.pid 
*.gz 

data/ 

pids 
logs 
results 

npm-debug.log 
node_modules 

.project 
.settings 

感谢, 鲍比

+1

显示你的** ** gitignore规则。 –

+0

正在更新... – bobbyg603

+1

您链接到一个页面,该页面讨论使用'git filter-branch'从您的历史记录中删除文件。这是正确的方法。你对这个过程有什么问题? – Chris

回答

99

感谢Chris我可以通过运行以下内容来解决此问题:

git filter-branch -f --index-filter'git rm --cached --ignore-unmatch pi/data/node-login.0'

git filter-branch -f --index-filter' git rm --cached --ignore-unmatch pi/data/node-login.1'

git filter-branch -f --index-filter'git rm --cached --ignore -unmatch pi/data/local.0'

+3

这帮了我很多,谢天谢地! –

+1

要小心,它会重写所有的历史记录。 – Utopik

+1

或者使用[BFG Repo Cleaner](https://rtyley.github.io/bfg-repo-cleaner/)。我已经完成了这两种方式,BFG更快,但需要更多的关心设置,而git filter-branch是一个很好的单线程。 – bradw2k

54
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all 

与文件替换FOLDERNAME或文件夹,你想从给定的Git库中删除。

+4

感谢上述,这是我唯一的解决方案! – stevensagaar

+1

完美无瑕!谢谢。我有一个java_pid文件的这个问题 – juliangonzalez

+2

美丽!这就像魅力一样。 – ricardohdz

2

我用BFG Repo Cleanner简单快捷,就像一个魅力

+0

这个解决方案对我来说非常合适!谢谢! :) –

15

这为我工作:

git rm --cached name_of_a_giant_file 
git rm --cached name_of_another_giant_file 
git commit --amend -CHEAD 
git push 

来源:Github Help: Working with large files

+1

什么都没有发生。虽然它应用了这个虽然它减少了文件总数,但是在显示过程99%之后它再次卡住了。任何建议我失踪了? – CoDe

+2

@ biscuit314请更新命令:git commit --amend -CHEAD – Anish

+0

这对我有用! – Aaron