2016-11-02 5 views
-2

初心者のgitのブランチ質問理解のgit支店

私は

<!DOCTYPE html> 
    <html> 

     <head> </head> 

    <body> 

     This is master 

    </body> 

    </html> 

のような単純なページを持っている場合は、そのブランチに新しいブランチとSWTCHクレタ

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

あなたはnew-branchで行った変更をコミットするのを忘れてしまっただけです。

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 

NB:最初のファイルを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