2017-07-17 31 views
1

我在名爲「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

這是絕對正常的git status輸出的最後一句話告訴你爲什麼:

沒有加入到承諾,但未跟蹤文件存在(使用「混帳添加」追蹤)

Git尚未跟蹤這些文件。他們不屬於任何分支,因爲他們從未被委託給知識庫。

您必須git add然後git commit爲了使這些文件屬於一個提交。分支只是一個指向提交的指針。

+0

好的,所以工作流應該是''(在分支新)add-> commit-> checkout master-> merge new'', 我是否正確? – BaRud

+1

你是對的。 – axiac

+1

瞭解更多關於[Git基礎知識](https://git-scm.com/book/en/v2/Getting-Started-Git-Basics)。 「三國」部分有一個很好的圖表。 – axiac

2

這是完全正常的,因爲你沒有提交這些文件。他們會跟着你的結賬,所以你可以在你想要的分支上提交它們。這是git的自然行爲。

相關問題