ウェブエンジニア珍道中

日々の技術的に関する経験を書いていきます。脱線もしますが助けになれば幸いです。

gitで編集したファイルのみaddするコマンド覚書

gitを使って開発していてブランチを行ったり来たりすると、
あるブランチにはaddしたくないような新規ファイルが出てきました。

個別にgit addを行うのは面倒なので、まとめて行う方法を調べてみたらありました。

git add -u

-uオプションつけるだけでOKです。

$ git status
On branch master
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:   hoge.md
    modified:   fuga.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    fuga.md

no changes added to commit (use "git add" and/or "git commit -a")

こういう状態の時にgit add -uと打つと

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   fuga.md
    modified:   hoge.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    foo.md

untracked filesはaddされずに編集したファイルだけaddされてます。
こういう小技も覚えると時短できていいですね。