How to stop tracking and ignore changes to a file in Git?
Just calling git rm --cached
on each of the files you want to remove from revision control should be fine. As long as your local ignore patterns are correct you won't see these files included in the output of git status.
Note that this solution removes the files from the repository, so all developers would need to maintain their own local (non-revision controlled) copies of the file
To prevent git from detecting changes in these files you should also use this command:
git update-index --assume-unchanged [path]
What you probably want to do: (from below @Ryan Taylor answer)
- This is to tell git you want your own independent version of the file or folder. For instance, you don't want to overwrite (or delete) production/staging config files.
git update-index --skip-worktree <path-name>
The full answer is here in this URL: http://source.kohlerville.com/2009/02/untrack-files-in-git/
There are 3 options, you probably want #3
1. This will keep the local file for you, but will delete it for anyone else when they pull.
git rm --cached <file-name>
or git rm -r --cached <folder-name>
2. This is for optimization, like a folder with a large number of files, e.g. SDKs that probably won't ever change. It tells git to stop checking that huge folder every time for changes, locally, since it won't have any. The assume-unchanged
index will be reset and file(s) overwritten if there are upstream changes to the file/folder (when you pull).
git update-index --assume-unchanged <path-name>
3. This is to tell git you want your own independent version of the file or folder. For instance, you don't want to overwrite (or delete) production/staging config files.
git update-index --skip-worktree <path-name>
It's important to know that git update-index
will not propagate with git, and each user will have to run it independently.
If you do git update-index --assume-unchanged file.csproj
, git won't check file.csproj for changes automatically: that will stop them coming up in git status whenever you change them. So you can mark all your .csproj files this way- although you'll have to manually mark any new ones that the upstream repo sends you. (If you have them in your .gitignore
or .git/info/exclude
, then ones you create will be ignored)
I'm not entirely sure what .csproj files are... if they're something along the lines of IDE configurations (similar to Eclipse's .eclipse and .classpath files) then I'd suggest they should simply never be source-controlled at all. On the other hand, if they're part of the build system (like Makefiles) then clearly they should--- and a way to pick up optional local changes (e.g. from a local.csproj a la config.mk) would be useful: divide the build up into global parts and local overrides.