2016-11-02 60 views
-2

新手的Git分支問題理解的Git分支

如果我有一個像

<!DOCTYPE html> 
    <html> 

     <head> </head> 

    <body> 

     This is master 

    </body> 

    </html> 

一個簡單的頁面,然後克里特島一個新的分支和動開關到分支

git branch new-branch 
    git checkout new-branch 

然後做的東西分支如

<!DOCTYPE html> 
    <html> 

     <head> </head> 

    <body> 

     This is master 

     This is in the new-branch 

    </body> 

    </html> 

我認爲這個新的分支將是從主機分開,如果我切換回主 它不會顯示內容中添加了新的分支

如果我簽了主

git checkout master 

它仍然顯示在新分支中添加的內容。

任何人都可以解釋爲什麼會發生這種情況。

+0

你沒有理會提交任何分支...... –

+0

https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-該系統信息庫 – 1615903

回答

0

你只是忘了提交你在新分支中所做的更改。

git checkout new-branch 

# Do your stuff in <edited_file> 

git add <edited_file> 
git commit -m "A short desc. of your changes" 
git checkout master 

注意:您應該先將您的初始文件提交到master分支。完整版:

git init . 

vim my_file   # Create some initial content in my_file 

git add my_file 
git commit -m "My first file" 

git branch new-branch 
git checkout new-branch 

vim my_file   # Add some line to my_file 

git add my_file 
git commit -m "Some new lines" 

git checkout master # my_file in master does NOT include changes made the second time