【问题标题】:File added to branch dev is showing in another branch when checking out and without merging visual studio [duplicate]签出时添加到分支 dev 的文件显示在另一个分支中且未合并 Visual Studio [重复]
【发布时间】:2021-10-06 19:04:07
【问题描述】:

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

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

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

【问题讨论】:

  • 修改文件的相同症状:stackoverflow.com/a/246298/7976758。在您的情况下,它是一个根本不属于 Git 的未跟踪文件。不去任何分支。
  • 未暂存文件是指未跟踪的文件。我,e git 不知道该文件属于哪个分支。因此,除非您明确地将其暂存到特定分支中,否则 git 将在所有分支中显示该文件。在您明确将该文件暂存到特定分支之前,在哪个分支中创建该文件确实无关紧要。

标签: git visual-studio version-control


【解决方案1】:

在它被提交到 git 之前(即当文件未被跟踪时),它不在 any 分支上。所以无论你在哪个分支,文件都会在本地。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2022-11-09
    • 2014-10-02
    • 2018-05-26
    • 1970-01-01
    相关资源
    最近更新 更多