2014-01-30 41 views
1

我正在學習git。我從我的主分支中創建了一個新的NEW分支,並在NEW中創建了一個新文件。現在,當我切換回主設備時,NEW中新創建的文件在主分支中可見。這是正常的嗎?如果是這樣,我如何隱藏主分支中其他分支的文件。來自其他分支的文件在主分支中可見

回答

2

直到您添加它(git add <file>)並且您提交它(git commit -m 'My new file'),您新創建的文件不是跟蹤。這意味着git沒有意識到它的索引樹中存在它。

所以你描述的行爲是完全可以預料的。這schema可能會幫助你瞭解(source)。

嘗試以下操作:

git checkout master   # start from the master branch 
git checkout -b NEW   # create and switch onto the NEW branch 
echo foo > bar    # create a new file 
git add bar     # track the file 
git commit -m 'My new file' # Commit the new file 
git checkout master   # The file has disappeared from the working directory 
+0

沒錯。我正在做同樣的事情。謝謝回覆。 –

相關問題