add & reset | 差分のステージとアンステージ (★)
// TODO: 概念図
難易度: :star:
概要
git add FILEで次のコミットにFILEの差分を含める (ステージ)git resetで次のコミットに含める差分をクリアする (アンステージ)git reset FILEで次のコミットからFILEの差分を除外する (アンステージ)
例題 (リポジトリ: git-drill/add-and-reset)
:computer:
index.htmlの内容に変更を加えた。:white_check_mark:
index.2.htmlをindex.htmlにコピー(上書き)
:computer:
style.cssの内容に変更を加えた。:white_check_mark:
style.2.htmlをstyle.cssにコピー(上書き)
:octocat:
index.htmlの変更をステージせよ:octocat:
index.htmlの変更をアンステージせよ:octocat:
index.htmlとstyle.cssの変更をステージせよ:octocat:
index.htmlとstyle.cssの変更をアンステージせよ
例題回答
git add index.htmlでindex.htmlをステージgit reset index.htmlでindex.htmlのみをアンステージgit add *
でindex.htmlとstyle.cssをステージ (git add index.html style.css`でも同じ)git reset
でindex.htmlとstyle.cssをアンステージ (git reset index.html style.css`でも同じ)
例題解説
git addコマンドは、、次のコミットに変更差分を含めるようgitに指示するためのコマンドです。 詳しくはadd & commitをご覧ください。
しかし誤ってgit addをした場合に、操作を取り消す(= 次のコミットに含める差分をクリアする)必要が生じる場合があります。 そのためのコマンドがgit resetです。
Last updated