显示在多个分支中的新文件

时间:2017-07-17 09:10:24

标签: git

我在名为" new"的分支中创建了一些文件,并在那里添加了一些文件。 但是,这些新文件也在master中显示。

$ git branch 
  gh-pages
* master
  modify
  new
$ git status 
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    scalable/apps/dbeaver.svg
    scalable/apps/kazam.svg
    scalable/apps/mysql-workbench.svg

nothing added to commit but untracked files present (use "git add" to track)
$ git checkout new 
Switched to branch 'new'
$ git status 
On branch new
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    scalable/apps/dbeaver.svg
    scalable/apps/kazam.svg
    scalable/apps/mysql-workbench.svg

nothing added to commit but untracked files present (use "git add" to track)

这是正常的吗?

2 个答案:

答案 0 :(得分:2)

这是完全正常的,因为您还没有提交这些文件。他们会关注您的结帐,因此您可以在所需的分支上提交它们。这是git的自然行为。

答案 1 :(得分:2)

绝对正常,git status输出的最后一句话告诉你原因:

  

没有添加到提交但未跟踪的文件存在(使用“git add”跟踪)

Git尚未跟踪这些文件。它们不属于任何分支,因为它们从未被提交到存储库。

您必须git add然后git commit才能使这些文件属于提交。分支只是提交的一个指针。