无法从git commit中删除文件

bob*_*603 68 git terminal github

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

我试图从我的c9.io项目强制覆盖存储在github上的项目的所有更改.我不小心git添加了一些mongodb数据文件.我试图将数据/目录添加到.gitignore.我从github撤出以获取更新的.gitignore,但是当我尝试git push时,这些数据/中的顽固文件仍然会进行提交.我还试图GIT中复位,GIT中底垫,GIT中清洁和其中我改变dmpfile.sql到pi /数据/节点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 git@github.com:bobbyg603/goddard.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:bobbyg603/goddard.git'
Run Code Online (Sandbox Code Playgroud)

的.gitignore:

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

data/

pids
logs
results

npm-debug.log
node_modules

.project
.settings
Run Code Online (Sandbox Code Playgroud)

谢谢,鲍比

bob*_*603 116

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

  • 小心,它改写了所有的历史。 (2认同)
  • 为了扩展 Sheraz 的评论,在 Windows 中确保使用双引号而不是单引号,并且如果您的路径和/或文件的名称中有空格,请用单引号将其括起来。所以`git filter-branch -f --index-filter "git rm --cached --ignore-unmatch 'path/with/spaces/in/file name.txt'"`。请参阅 /sf/answers/2361935551/。还要确保您在正确的目录中! (2认同)

Gan*_*ank 67

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all
Run Code Online (Sandbox Code Playgroud)

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


bis*_*314 18

这对我有用:

git rm --cached name_of_a_giant_file
git rm --cached name_of_another_giant_file
git commit --amend -CHEAD
git push
Run Code Online (Sandbox Code Playgroud)

来源:Github帮助:使用大文件

  • 什么都没发生。应用此方法后,虽然它减少了文件总数,但在显示进程 99% 后,它又卡住了。我缺少什么建议? (2认同)
  • @ biscuit314请更新命令:git commit --amend -CHEAD (2认同)

ack*_*ser 6

git filter-branch --tree-filter 'rm -rf path/whaever' HEAD
Run Code Online (Sandbox Code Playgroud)

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

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

现在,我可以推