无法从 git commit 中删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21168846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't remove file from git commit
提问by bobbyg603
How do I discard all git commits that haven't been pushed and then force git to not commit anything in the data/ directory?
如何丢弃所有尚未推送的 git 提交,然后强制 git 在 data/ 目录中不提交任何内容?
I'm trying to force overwrite all changes to a project stored on github from my c9.io project. I accidentally git added some mongodb data files. I tried to add the data/ directory to .gitignore. I pulled from github to get the updated .gitignore, however when I try and git push, these stubborn files in data/ are still staged for commit. I also tried git reset, git rebase, git clean and thiswhere I changed dmpfile.sql to pi/data/node-login.1.
我试图从我的 c9.io 项目强制覆盖对存储在 github 上的项目的所有更改。我不小心 git 添加了一些 mongodb 数据文件。我试图将 data/ 目录添加到 .gitignore。我从 github 中拉取更新的 .gitignore,但是当我尝试 git push 时,data/ 中的这些顽固文件仍处于提交阶段。我还试图GIT中复位,GIT中底垫,GIT中清洁和这其中我改变dmpfile.sql到pi /数据/节点login.1。
Please help I've been at this for hours and I'm really frustrated
请帮助我已经在这工作了几个小时,我真的很沮丧
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:
.gitignore:
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
data/
pids
logs
results
npm-debug.log
node_modules
.project
.settings
Thanks, Bobby
谢谢,鲍比
回答by bobbyg603
Thanks to Chris I was able to fix this by running the following:
感谢 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'
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'
回答by Gank
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all
replace FOLDERNAME with the file or folder you wish to remove from the given git repository.
将 FOLDERNAME 替换为您希望从给定 git 存储库中删除的文件或文件夹。
回答by biscuit314
This worked for me:
这对我有用:
git rm --cached name_of_a_giant_file
git rm --cached name_of_another_giant_file
git commit --amend -CHEAD
git push
回答by Victor Laerte
I've used BFG Repo Cleannersimple and fast, works like a charm
我已经使用BFG Repo Cleanner简单快速,效果很好
回答by ackuser
git filter-branch --tree-filter 'rm -rf path/whaever' HEAD
This is a little bit simpler and it is a way to just remove and rewrite it from the history. That's the result
这有点简单,它是一种从历史记录中删除和重写它的方法。结果就是这样
Rewrite 5ac3045254d33fc5bb2b9fb05dccbdbb986b1885 (61/62) (24 seconds passed, remaining 0 predicted)
Ref 'refs/heads/features_X' was rewritten
Now, I can push
现在,我可以推