0

https://git-scm.com/docs/git-rm

Say I run a commit but then I realize that I have just committed files that I don't wish to commit

if I run git rm on a file, it will literally delete the file from my project and the filesystem.

I just want to remove the file from the most recent commit and stop tracking it - basically gitignoring retroactively!

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

2 Answers2

3

You have to edit or undo the last commit.

Have a look at a similar Question: Remove files from Git commit

Community
  • 1
  • 1
sleeplessnerd
  • 21,853
  • 1
  • 25
  • 29
2

git rm has done what it is expected to do. To stop tracking the file you need to add the file path in your .gitignore file.

and to revert the changes back, use

git reset --soft HEAD~1
rajuGT
  • 6,224
  • 2
  • 26
  • 44
  • yes but what if I dont want to reset all the files just the one or two files that I wish to gitignore? – Alexander Mills Oct 17 '15 at 22:57
  • The link in the answer, will show many possible ways to ignore the git file by path/pattern. You can also make gitignore to track only files you want to track like this http://stackoverflow.com/questions/33189437/explain-gitignore-pattern-matching/33190653#33190653 but I highly recommend not to use this pattern. If you like to reset only particular file check this answer http://stackoverflow.com/a/215731/1699979 – rajuGT Oct 19 '15 at 20:48