git 助けて 間違ってaddしてしまったのを取り消して前のインデックスの状態を手に入れたい
— トデス子 (@todesking) October 5, 2012
私がやりたいのはですね、 git add a; git add b; した状態からgit add a;した状態に戻したい
— トデス子 (@todesking) October 5, 2012
例えが悪かった、git add a; edit a; git add a;した状態から二度目のgit add aの影響を巻き戻したい
— トデス子 (@todesking) October 5, 2012
それ git reset --patch
でできるよ。
git reset (--patch | -p) [<commit>] [--] [<paths>...]
Interactively select hunks in the difference between the index and <commit> (defaults to
HEAD). The chosen hunks are applied in reverse to the index.
This means that git reset -p is the opposite of git add -p, i.e. you can use it to
selectively reset hunks. See the `Interactive Mode'' section of linkgit:git-add[1] to
learn how to operate the `--patch mode.
git add
しすぎた状態。下の方の差分はまだコミットしたくないのでインデックスから取り除きたい。
そこでおもむろに git reset -p
とすると、 git add -p
と同じ感じになるので同じ感じに操作するとインデックスから取り除ける。要するに git add -p
の真逆のことができる。
便利ですね!!