実行前の状態
README.md を 1 回コミットした
Git では、
この
ターミナル
git init -q -b main hello
cd hello
echo "# hello" > README.md
git add README.md
git commit -q -m "README を作る"
echo "start" >> README.md
echo "print('hi')" > app.py最小の例と結果
add はgit status を
ターミナル
git add app.py
git statusOn branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: app.py
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.mdChanges to be committedの下が、 次の コミットに 入る物です。 app.py が 移ってきました。 - README.md は add していないので、
Changes not staged for commitに残ったままです。
成功の確認
短い形の status で、A (新しいM (変更) が
ターミナル
git status -s M README.md
A app.pyapp.py のA は、?? はUU は
構文と 主要オプション
| 書き方 | すること |
|---|---|
git add <ファイル> | 指定した |
git add . | いまの |
git add -A | リポジトリ全体の |
git add -u | 記録済みの |
git add -p | 変更を |
失敗時の戻し方
add しても、
ターミナル
git restore --staged app.pyまだ 1 回もgit rm --cached app.py で--cached をgit rm を
git restore app.py のように --staged を--staged を
よくある疑問
衝突を 直した あと、 なぜ add するのですか
merge や pull でgit status に both modified と<<<<<<< から >>>>>>> までのgit add します。
全部のgit commit、git rebase --continue でgit merge --abort、git rebase --abort で
add した あとに ファイルを また直したら、 どうなりますか
ステージにgit add します。git status で
空の フォルダを add しても、 何も 載りません
Git が.gitkeep などの
