Skip to content
Fix Code Error

How to stop tracking and ignore changes to a file in Git?

March 13, 2021 by Code Error
Posted By: Anonymous

I have cloned a project that includes some .csproj files. I don’t need/like my local csproj files being tracked by Git (or being brought up when creating a patch), but clearly they are needed in the project.

I have added *.csproj to my LOCAL .gitignore, but the files are already in the repo.

When I type git status, it shows my changes to csproj which I am not interested in keeping track of or submitting for patches.

How do I remove the “tracking of” these files from my personal repo (but keep them in the source so I can use them) so that I don’t see the changes when I do a status (or create a patch)?

Is there a correct/canonical way to handle this situation?

Solution

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)

  1. 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/

Answered By: Anonymous

Related Articles

  • Is CSS Turing complete?
  • Why call git branch --unset-upstream to fixup?
  • Various ways to remove local Git changes
  • Use of PUT vs PATCH methods in REST API real life scenarios
  • Why do I have to "git push --set-upstream origin "?
  • Git - Pushing code to two remotes
  • Git command to show which specific files are ignored by…
  • error LNK2005: ✘✘✘ already defined in…
  • Checkout another branch when there are uncommitted changes…
  • Setting Different Bar color in matplotlib Python

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Split Strings into words with multiple word boundary delimiters

Next Post:

Convert UTC date time to local date time

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error