git stage / unstage


概要

git stage / git unstage というコマンドが便利。

git stagegit add のシノニム(synonym)。

Git - git-stage Documentation
https://git-scm.com/docs/git-stage

git unstage というコマンドは存在しないので、エイリアス(alias)を作る。

~/.gitconfig
[alias]
    unstage = reset HEAD

使い方

readme というファイルを編集していると想定する。

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   readme

no changes added to commit (use "git add" and/or "git commit -a")

git stagereadme ファイルを staged 状態にする。

$ git stage .
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   readme

先ほど作った git unstage を使う。stagedunstaged 状態に戻る。

$ git unstage
Unstaged changes after reset:
M   readme

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   readme

no changes added to commit (use "git add" and/or "git commit -a")

まとめ

既存のコマンドの代わりに覚えやすい別名を使うことで、脳のメモリ(記憶)を節約する。

git add git stage
git reset HEAD git unstage