1

I have already committed a lot of files to my current repository (I haven't pushed them yet). However, many of these files that a lot of space and I shouldn't include them. I have updated my .gitignore accordingly to remove them, however my question is how to prevent these files from being pushed to the repository now?

I have tried git rm -r folder and it has actually deleted my entire folder on this. I just want to delete these files from the current commit. How can I do this?

Roope
  • 4,469
  • 2
  • 27
  • 51
Crista23
  • 3,203
  • 9
  • 47
  • 60
  • 1
    Did you google and use the search for e.g. "gitignore after commit"? – Roope Oct 13 '16 at 22:07
  • Thanks, excellent suggestion! Found the response here: http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files – Crista23 Oct 13 '16 at 22:53

2 Answers2

1

I have found the solution here:

Applying .gitignore to committed files

"After editing .gitignore to match the ignored files, you can do git ls-files -ci --exclude-standard to see the files that are included in the exclude lists; you can then do git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached to remove them from the repository (without deleting them from disk)."

Community
  • 1
  • 1
Crista23
  • 3,203
  • 9
  • 47
  • 60
0

One option is to undo the commit and staging, you could try doing

git reset HEAD^

This command would reset the repo to previous commmit, however all the changes you did would still be available.

raghurok
  • 103
  • 2
  • 6
  • Thanks! I have actually done 3 commits which haven't been pushed. Does this mean I should use git reset HEAD^ 3 times to reach the previous state? – Crista23 Oct 13 '16 at 22:15