Git on Visual Studio 显示来自另一个分支的文件

Git on Visual Studio shows files from another branch

我在 Visual Studio 2017 年做了以下测试:

1) 使用 master 分支创建了新的 repo:

它只有一个 gitginore 文件:

2) 使用 file1 创建了 Branch1:

3) 再次checkout master分支,打开'Show folder view':

为什么我在 master 分支中看到 file1?

如果您在分支之间移动但不想提交,只需隐藏您的更改。

它会清理你的环境,这样当你搬到另一个分支时,什么也不会留下。您将拥有一个干净的环境。

当您回到上一个分支时,您可以取消隐藏。

如果您熟悉 TFS,那么存储就像一个货架集。

看看https://git-scm.com/docs/git-stash

Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

客户端(Visual Studio)和服务器端(Azure DevOps)都是Git的标准实现

正如评论中提到的,这是 Git 中的过期行为。

创建的文件 (file1) 在您添加并提交它们之前不会放入存储库中。

如果您切换回 Branch1 分支并提交 文件,那么它不会再出现在主分支上。