添加到分支 dev 的文件在签出时显示在另一个分支中且未合并 Visual Studio

我有两个分支 devbugfix

在开发上我创建了新文件 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)

有人可以向我解释这种行为吗?为什么这个文件在他们之间共享? 我开始知道我应该在签出之前暂存然后隐藏这个文件。

但我仍然想了解这种行为。为什么不只为 dev 分支保留它? 有时我会忘记在结账之前暂存和隐藏更改,这会造成很大的混乱

a1119850405 回答:添加到分支 dev 的文件在签出时显示在另一个分支中且未合并 Visual Studio

直到它被提交到 git 中(即当文件未被跟踪时),它不在 任何 分支上。因此,无论您在哪个分支上,该文件仍会在本地。

本文链接:https://www.f2er.com/4482.html

大家都在问