Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove from git but keep in working directory

Tags:

git

I added a bunch of files to be tracked by git, but they were added (and committed) in error. They should be present in the working directory (they're ephemeral files used by my IDE), but not tracked by git. I've now created a .gitignore file and added the appropriate entries, but what is the proper way to remove the files from being tracked by git while leaving them safely in my working directory?

like image 851
Matty Avatar asked Aug 22 '11 01:08

Matty


2 Answers

Use the --cached option:

git rm --cached myfile

Complete explanation here: http://www.kernel.org/pub/software/scm/git/docs/git-rm.html

I also like the --dry-run option. It does not actually change anything, just show what files will be impacted by the real command. It's good to start with that to see what will happen, or to test your file name pattern.

like image 172
Blacksad Avatar answered Nov 05 '22 17:11

Blacksad


git rm --cached will remove the files from your index but will keep them in your working directory.

like image 40
Ulrich Dangel Avatar answered Nov 05 '22 18:11

Ulrich Dangel