2016年3月2日水曜日

git commitで特定ファイルのみコミットする

gitでコミットするときにステージング済みのファイルから一部のファイルだけコミットする場合は、
git commit -- file listのように、コミット対象のfile listを指定する。

■コミット前のステータス
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   fuga.txt
        new file:   hoge.txt

■コミット
$ git commit -m 'add' -- hoge.txt
[master (root-commit) fb9d957] add
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 hoge.txt

■コミット後のステータス
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   fuga.txt

■複数ファイルの場合はスペースで区切る
$ git commit -m 'mod' -- hoge.txt piyo.txt