* git add -p (パッチをadd) [#vd1345b4]


*** ステージングする [#f6c45908]
1. git add -pで対話的にaddする。

 $ git add -p 1.txt
 diff --git a/1.txt b/1.txt
 index 01e79c3..280c8b8 100644
 --- a/1.txt
 +++ b/1.txt
 @@ -1,3 +1,5 @@
  1
 +a
  2
  3
 +b
 Stage this hunk [y,n,q,a,d,/,s,e,?]? 

2. sを選び、hunkをsplitする。
 Stage this hunk [y,n,q,a,d,/,s,e,?]? s
 Split into 2 hunks.
 @@ -1,3 +1,4 @@
  1
 +a
  2
  3
 Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?

3. yを選び、このhunkをaddする。
 Split into 2 hunks.
 @@ -1,3 +1,4 @@
  1
 +a
  2
  3
 Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?y

4. nを選び、このhunkをaddしない。
 @@ -2,2 +3,3 @@
  2
  3
 +b
 Stage this hunk [y,n,q,a,d,/,K,g,e,?]?n

これでステージングが終わった。


*** ステージング状態の確認 [#c4c38b84]
git statusで確認。
 $ git st
 # On branch master
 # Changes to be committed:
 #   (use "git reset HEAD <file>..." to unstage)
 #
 #       modified:   1.txt
 #
 # Changes not staged for commit:
 #   (use "git add <file>..." to update what will be committed)
 #   (use "git checkout -- <file>..." to discard changes in working directory)
 #
 #       modified:   1.txt
 #

git diff --cachedでも確認。
 $ git diff --cached 1.txt
 diff --git a/1.txt b/1.txt
 index 01e79c3..1920040 100644
 --- a/1.txt
 +++ b/1.txt
 @@ -1,3 +1,4 @@
  1
 +a
  2
  3

*** commitする [#bf6c23b4]
 $ git commit -m 'modify #1' 1.txt
 $ git commit -m 'modify #1' 1.txt


*** 改めてgit diff [#oa7ad498]

 $ git diff
 diff --git a/1.txt b/1.txt
 index 1920040..280c8b8 100644
 --- a/1.txt
 +++ b/1.txt
 @@ -2,3 +2,4 @@
  a
  2
  3
 +b 

*** 2回目のaddとcommit [#lb8bcacf]

 $ git add 1.txt
 $ git commit 1.txt -m 'modify #2'


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