0

I've got a file that is currently tracked and needs to remain in the repository but I don't want my current changes to it to constantly show up in Sourcetree.

All the posts I'm finding here say to stop tracking the file a la: git rm --cached but then committing it will remove it from the remote repo, right? Or am I totally misunderstanding it?

Because as soon as I stop tracking it it shows up with a red minus icon and shows that it needs to be committed.

How can I ignore my local changes to a file that must remain in the repo?

Thanks for any helpful tips.

fumeng
  • 1,771
  • 5
  • 22
  • 61
  • 4
    Possible duplicate of [How to stop tracking and ignore changes to a file in Git?](https://stackoverflow.com/questions/936249/how-to-stop-tracking-and-ignore-changes-to-a-file-in-git) – phd Jan 30 '18 at 19:54
  • 2
    `git update-index --assume-unchanged` – phd Jan 30 '18 at 19:55
  • 1
    Note that the phrase *remove it from the remote repo* makes no sense. The remote repository is a large collection of commits; it's *not* a set of files. If the remote repository is a `--bare` repository, the remote repository has no work-tree at all. If the remote repository does have a work-tree, that work-tree contains files, and you could say *will remove it from the work-tree of the remote repo* (to which the answer is: maybe; that depends on additional items). – torek Jan 30 '18 at 21:01
  • @phd - thank you for the link to that post, that's exactly what I needed. – fumeng Jan 30 '18 at 22:31
  • @torek - thank you for the explanation. – fumeng Jan 31 '18 at 15:27

1 Answers1

1

You can add the file to .gitignore. The nice thing about .gitignore is that if you ignore a file that is already committed, it will remain in the in the branch unchanged and your local changes to it will not show up in git diff and will not be included in any of your commits. The down side is that if anyone wants to change the file later, they will have to temporarily remove it from .gitignore to make the change.

Some projects like Apex https://github.com/apache/apex-core use this technique to commit IDE settings, so that developers can have their IDE configured with the project defaults, but they don't accidentally commit any changes to their IDE settings. If you follow the link you'll notice a .idea folder is committed to the repository and that .idea is included in the .gitignore file.

ilooner
  • 2,480
  • 15
  • 32