Git 複数個所の変更を選択して add
2箇所離れている場所を変更して
git add -pを利用すると変更箇所ごとに確認が出ます。
$ git add -p diff --git a/test.txt b/test.txt index 43eb1f4..63b004f 100644 --- a/test.txt +++ b/test.txt @@ -1,6 +1,7 @@ test a -2 +b +30 3 4 x Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y @@ -36,4 +37,5 @@ z 111 +99999 212 Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n
これで上の更新のみaddされます。
$ git diff diff --git a/test.txt b/test.txt index d10d14a..63b004f 100644 --- a/test.txt +++ b/test.txt @@ -37,4 +37,5 @@ z 111 +99999 212
下の更新はまだaddしていません。
add下部分のみの確認は
$ git diff --cached diff --git a/test.txt b/test.txt index 43eb1f4..d10d14a 100644 --- a/test.txt +++ b/test.txt @@ -1,6 +1,7 @@ test a -2 +b +30 3 4 x
* text.txtを変更 & test2.txtを作成を追加します。
$ git add -A ↑ git add . && git add -u と同じ意味です。
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD..." to unstage) # # modified: test.txt # new file: test2.txt #
text.txtのadd をやめる。
$ git reset test.txt Unstaged changes after reset: M test.txt
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD..." to unstage) # # new file: test2.txt # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: test.txt #
git commit -v で diff –cached と commitを一気に。
$ git commit -v add test2 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD..." to unstage) # # new file: test2.txt # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: test.txt # diff --git a/test2.txt b/test2.txt new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/test2.txt @@ -0,0 +1 @@ +test
これで保存。
".git/COMMIT_EDITMSG" 22L, 597C written [master 6e2f6c7] add test2 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 test2.txt
- Prev Git init, add, commit
- Next Git bareリポジトリの作成, push,pull
- Prev Git init, add, commit
- Next Cygwin で Git