首页 > 解决方案 > 签出且未合并 Visual Studio 时,添加到分支 dev 的文件显示在另一个分支中

问题描述

我有两个分支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)

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

但我仍然想了解这种行为。为什么不只为开发分支保留它?有时我忘记在结帐前准备和存储更改,这会造成巨大的混乱

标签: gitvisual-studioversion-control

解决方案


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


推荐阅读