* ステージングを取り消す(INDEXを戻す) [#l4334612]

** あるファイルのステージングを取り消す [#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 と省略せずに指定してもいい

** まとめて複数のファイルのステージングを取り消す [#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したファイルのステージングを取り消す [#n8aba5ae]

 git rm --cached test.txt

- 一度もコミットしていないと、git reset HEADしようとしても以下のようなエラーが出る。

>fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS