2014-01-16 66 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