Reputation: 259
I ran the command git update-index --assume-unchanged .\src\main\resources\application.properties
in my local directory, and the application.properties
file disappeared from the Changes
section of Source Control
in VS Code, as I expected.
However, the diff still shows red deletions & green additions, as if the file is still being tracked. <-- this is shown in the screenshot below
I'm also prevent from switching branches, for the reason that "changes would overwrite that file"
Any ideas why this is happening? I want a base version in my remote repository that I can change locally without the changes being tracked.
I saw the --skip-worktree
option and tried git update-index --skip-worktree .\src\main\resources\application.properties
, but got the same results.
Here's the git commands & output
PS C:\r\Body-Tracking-Uploader> git update-index --assume-unchanged .\src\main\resources\application.properties
PS C:\r\Body-Tracking-Uploader> git status
On branch upload-exerciseInfo-aws
Your branch is up to date with 'origin/upload-exerciseInfo-aws'.
nothing to commit, working tree clean
PS C:\r\Body-Tracking-Uploader> git branch
main
* upload-exerciseInfo-aws
PS C:\r\Body-Tracking-Uploader> git checkout main
error: Your local changes to the following files would be overwritten by checkout:
src/main/resources/application.properties
Please commit your changes or stash them before you switch branches.
Aborting
PS C:\r\Body-Tracking-Uploader>
Upvotes: 0
Views: 325
Reputation: 76459
You're looking for a way to ignore changes to tracked files, and the reason neither of the options you've tried work is because Git doesn't support that, as outlined in the Git FAQ:
Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.
It’s tempting to try to use certain features of git update-index, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.
If you're looking for a way to deal with configuration in config files, which is what it looks like you're doing, then the FAQ outlines how to do that:
If your goal is to modify a configuration file, it can often be helpful to have a file checked into the repository which is a template or set of defaults which can then be copied alongside and modified as appropriate. This second, modified file is usually ignored to prevent accidentally committing it.
Upvotes: 3
Reputation: 259
I'm not totally sure what the problem was, but I took the following steps
main
(it's not feature-complete yet, but functions in its current state)main
in the remote repository (to continue the previous WIP feature)main
into my localgit update-index --skip-worktree .\src\main\resources\application.properties
Now the changes do not show in the Source Control view, and they don't prevent me from moving between branches locally.
Upvotes: -1