2016-11-02 59 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