【发布时间】:2021-10-06 19:04:07
【问题描述】:
我有两个分支dev 和bugfix
在开发上我创建了新文件TestClass.cs 这个文件没有暂存。
如果我运行 git status 它会显示
On branch dev
Untracked files:
(use "git add <file>..." to include in what will be committed)
WebApplication1/TestClass.cs
nothing added to commit but untracked files present (use "git add" to track)
然后我运行git checkout bugfix
现在我也可以在这个分支中看到新添加的类TestClass.cs了。
所以如果我运行 git status 它会显示
On branch bugfix
Untracked files:
(use "git add <file>..." to include in what will be committed)
WebApplication1/TestClass.cs
nothing added to commit but untracked files present (use "git add" to track)
有人可以向我解释这种行为吗?为什么这个文件在他们之间共享? 我开始知道我应该在签出之前先暂存该文件。
但我仍然想了解这种行为。为什么不只为开发分支保留它? 有时我忘记在结帐前暂存和存储更改,这会造成很大的混乱
【问题讨论】:
-
修改文件的相同症状:stackoverflow.com/a/246298/7976758。在您的情况下,它是一个根本不属于 Git 的未跟踪文件。不去任何分支。
-
未暂存文件是指未跟踪的文件。我,e git 不知道该文件属于哪个分支。因此,除非您明确地将其暂存到特定分支中,否则 git 将在所有分支中显示该文件。在您明确将该文件暂存到特定分支之前,在哪个分支中创建该文件确实无关紧要。
标签: git visual-studio version-control