git add

git

書き方

git add [-A|-u|-p] <pathspec>...

今この瞬間のファイルの中身をコミット待ちに載せます。addした後にまた直すとその修正は入らないので、もう一度addします。

よく使うオプション

オプション意味
-Astage every change in the whole tree, deletions included
-ustage changes to tracked files only, no new files
-pwalk the diff and choose hunk by hunk
-ndry run: list what would be staged
-fstage a file that .gitignore excludes
-Nrecord the path only, so the file shows up in diffs

git add -A

stages everything, including files you deleted

git add -p src/app.ts

stages part of one file and leaves the rest

git add .

stages everything under the current directory

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git add は何をしますか。

今この瞬間のファイルの中身をコミット待ちに載せます。addした後にまた直すとその修正は入らないので、もう一度addします。

Q. どう打ちますか。

git add [-A|-u|-p] <pathspec>... — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-add