简体   繁体   中英

Stop tracking local changes on a tracked file

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM