適用場合:git commit
したけど git push
をしていない。
$ git status
(use "git reset HEAD <file>..." to unstage)
modified: filea.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
fileb.txt
filea
は修正したファイルで、 fileb
は新規ファイルです。
filea
のみを commit
したいけど、あやまって:
$ git add .
$ git commit -m "msg"
で2つのファイルを全部 commit
した。
新規ファイル fileb
を取り戻したいなら、下記に手順で行います:
一つ前の commit
履歴に戻ります:
$ git reset --soft HEAD^
これでは git add .
の状態に戻り、 git status
で確認できます:
$ git status
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: fileb.txt
modified: filea.txt
提示の通り、 git reset HEAD
で fileb
を staging
領域から外します。
$ git reset HEAD fileb.txt
$ git status
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: filea.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
new file: fileb.txt
再び git commit
この状態でも一度 commit
すれば良いです:
$ git commit -m "msg"
もしすでにリモートレポジトリにPUSHしましたら、 git push -f
は使えるのではないか。