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.htmlindex.html にコピー(上書き)

  • :computer: style.css の内容に変更を加えた。

    • :white_check_mark: style.2.htmlstyle.css にコピー(上書き)

  • :octocat: index.htmlの変更をステージせよ

  • :octocat: index.htmlの変更をアンステージせよ

  • :octocat: index.htmlstyle.cssの変更をステージせよ

  • :octocat: index.htmlstyle.cssの変更をアンステージせよ

例題回答

  • git add index.htmlindex.htmlをステージ

  • git reset index.htmlindex.htmlのみをアンステージ

  • git add *index.htmlstyle.cssをステージ (git add index.html style.css`でも同じ)

  • git resetindex.htmlstyle.cssをアンステージ (git reset index.html style.css`でも同じ)

例題解説

git addコマンドは、、次のコミットに変更差分を含めるようgitに指示するためのコマンドです。 詳しくはadd & commitをご覧ください。

しかし誤ってgit addをした場合に、操作を取り消す(= 次のコミットに含める差分をクリアする)必要が生じる場合があります。 そのためのコマンドがgit resetです。

Last updated