git add -p (パッチをadd)

ステージングする

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

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

ステージング状態の確認

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する

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

改めてgit diff

 $ 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

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

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

Last-modified: 2012-01-31 (火) 19:20:13