Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't remove file from git commit

How do I discard all git commits that haven't been pushed and then force git to not commit anything in the data/ directory?

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 this where I changed dmpfile.sql to pi/data/node-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:

lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz  data/  pids logs results  npm-debug.log node_modules  .project .settings 

Thanks, Bobby

like image 567
bobbyg603 Avatar asked Jan 16 '14 17:01

bobbyg603


People also ask

How do I remove a file from a git commit?

If this is your last commit and you want to completely delete the file from your local and the remote repository, you can: remove the file git rm <file> commit with amend flag: git commit --amend.

How do I delete a large file from a commit?

If the large file was added in the most recent commit, you can just run: git rm --cached <filename> to remove the large file, then. git commit --amend -C HEAD to edit the commit.


2 Answers

Thanks to Chris I was able to fix this by running the following:

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'

like image 188
bobbyg603 Avatar answered Oct 15 '22 21:10

bobbyg603


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.

like image 37
Gank Avatar answered Oct 15 '22 23:10

Gank