【发布时间】:2021-07-08 18:13:14
【问题描述】:
我在本地目录中运行了命令git update-index --assume-unchanged .\src\main\resources\application.properties,正如我所料,application.properties 文件从 VS Code 中Source Control 的Changes 部分消失了。
但是,差异仍然显示红色删除和绿色添加,就好像文件仍在被跟踪一样。
我也阻止切换分支,因为“更改会覆盖该文件”
任何想法为什么会发生这种情况?我想在我的远程存储库中有一个基本版本,我可以在本地更改而不跟踪更改。
我看到了--skip-worktree 选项并尝试了git update-index --skip-worktree .\src\main\resources\application.properties,但得到了相同的结果。
这是 git 命令和输出
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>
【问题讨论】:
-
我认为问题在于您已指示 git 不在乎对文件本地进行的更改....但是,这并不排除其他人其他 repos 提交对所述文件的更改....所以,现在 git 告诉您,如果您签出,您对文件的 local 更改将被来自另一个分支的更改覆盖.总而言之,为了不破坏您的本地更改,它的行为非常符合预期。
-
从技术上讲,当且仅当文件在 Git 的索引中时,文件才会被跟踪。要设置标志(假设未更改或跳过工作树),文件必须在 Git 的索引中:标志是该文件的索引条目的一部分。所以当然文件仍然被跟踪。你需要它!
标签: git github git-assume-unchanged