ブランチ作成時と現在をスリードット(...)で比較する

スリードットで比較すると何が起きるのか?

 git diff master...branch1
  • masterブランチからbranch1ブランチを作成した時の状態と現在のbranch1ブランチの状態の比較を行う

前提

 (1) git co master
 (2) git co -b branch1
 (3) vi 1.txt
 (4) git add 1.txt; git commit -m 'Changed 1.txt'
 (5) git co master
 (6) vi 2.txt
 (7) git add 2.txt; git commit -m 'Changed 2.txt'
  • (1) masterブランチに入る
  • (2) masterブランチからbranch1ブランチを作って入る
  • (3) (4) 1.txtファイルを編集してAddしてCommitする
  • (5) masterブランチに入る
  • (6) (7) 2.txtファイルを編集してAddしてCommitする

ブランチ作成時と現在をスリードット(...)で比較する

 git diff master...branch1
 
 diff --git a/1.txt b/1.txt
 index 58c9bdf..2e6bfd4 100644
 --- a/1.txt
 +++ b/1.txt
 @@ -1 +1 @@
 -111
 +111X
  • 上のようにbranch1ブランチ作成時のmasterと現在のbranch1を比較するので、1.txtだけ表示される
  • また、branch1ブランチ作成時のmasterの状態(=コミット)のことをマージベース(Merge Base)と呼ぶ

ツードット(..)で比較すると

 git diff master..branch1
 
 diff --git a/1.txt b/1.txt
 index 58c9bdf..2e6bfd4 100644
 --- a/1.txt
 +++ b/1.txt
 @@ -1 +1 @@
 -111
 +111X
 diff --git a/2.txt b/2.txt
 index e7a15fa..c200906 100644
 --- a/2.txt
 +++ b/2.txt
 @@ -1 +1 @@
 -222Y
 +222
  • master1ブランチ作成後のコミットである2.txtも表示される
  • すなわち、最新のmasterブランチと最新のbranch1ブランチを比較していることになる
  • なお、git diff master..branch1git diff master branch1としても同じでどちらでもよい

(補足) git logのスリードットはgit diffとは意味が違うので注意する

https://stackoverflow.com/questions/7251477/what-are-the-differences-between-double-dot-and-triple-dot-in-git-dif/7256391

参考

https://stackoverflow.com/questions/7251477/what-are-the-differences-between-double-dot-and-triple-dot-in-git-dif/7256391


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2021-01-15 (金) 11:32:17