- 追加された行はこの色です。
- 削除された行はこの色です。
* ステージングを取り消す(INDEXを戻す) [#l4334612]
*** あるファイルのステージングを取り消す [#qe9066fa]
** あるファイルのステージングを取り消す [#j1d905d6]
vi test.txt # (1) test.txtを修正する
git add test.txt # (2) test.txtをステージングする
git reset HEAD test.txt # (3) 上のステージングを取り消す(INDEXをHEADに戻す)
# test.txtは修正されたまま(INDEXがHEADに戻っただけで、ワーキングツリーはそのまま)
- git reset HEAD の代わりに git reset --mixed HEAD と省略せずに指定してもいい
*** 修正したファイル戻す [#pac0f7ec]
** まとめて複数のファイルのステージングを取り消す [#d49ed4af]
*** ステージングしたファイルの一覧を取得する [#t04102b5]
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: 1.txt
modified: 2.txt
modified: 3.txt
$ git diff --cached --name-only
1.txt
2.txt
3.txt
*** ステージングしたファイルの一覧をまとめて取り消す [#vd3639d4]
PowerShell> git reset HEAD (git diff --cached --name-only)
Bash> git reset HEAD $(git diff --cached --name-only)
- https://stackoverflow.com/questions/2298047/git-ls-files-howto-identify-new-files-added-not-committed
** 修正したファイル戻す [#q7f621d6]
git checkout test.txt # test.txtは(1)で修正される前の状態に戻った。
*** 一度もコミットしてない状態でADDしたファイルのステージングを取り消す [#ca5c8a74]
** 一度もコミットしてない状態でADDしたファイルのステージングを取り消す [#n8aba5ae]
git rm --cached test.txt
- 一度もコミットしていないと、git reset HEADしようとしても以下のようなエラーが出る。
>fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.