git add
git
書き方
git add [-A|-u|-p] <pathspec>...今この瞬間のファイルの中身をコミット待ちに載せます。addした後にまた直すとその修正は入らないので、もう一度addします。
よく使うオプション
| オプション | 意味 |
|---|---|
| -A | stage every change in the whole tree, deletions included |
| -u | stage changes to tracked files only, no new files |
| -p | walk the diff and choose hunk by hunk |
| -n | dry run: list what would be staged |
| -f | stage a file that .gitignore excludes |
| -N | record the path only, so the file shows up in diffs |
例
git add -Astages everything, including files you deleted
git add -p src/app.tsstages 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