无法从git commit中删除文件

问题描述 投票:65回答:5

如何丢弃所有未被推送的git提交然后强制git不在数据/目录中提交任何内容?

我试图从我的c9.io项目强制覆盖存储在github上的项目的所有更改。我不小心git添加了一些mongodb数据文件。我试图将数据/目录添加到.gitignore。我从github撤出以获取更新的.gitignore,但是当我尝试git push时,这些数据/中的顽固文件仍然会进行提交。我还尝试了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

谢谢,鲍比

git github terminal
5个回答
113
投票

感谢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'


67
投票
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all

将FOLDER NAME替换为您要从给定git存储库中删除的文件或文件夹。


17
投票

这对我有用:

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


2
投票

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


1
投票
git filter-branch --tree-filter 'rm -rf path/whaever' HEAD

这有点简单,它是一种从历史中删除和重写它的方法。结果就是这样

Rewrite 5ac3045254d33fc5bb2b9fb05dccbdbb986b1885 (61/62) (24 seconds passed, remaining 0 predicted)
Ref 'refs/heads/features_X' was rewritten

现在,我可以推动

© www.soinside.com 2019 - 2024. All rights reserved.