0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

git init直後のstaging, commit取消

Posted at

git init直後のstaging, commit取消

普段ならstagingの取り消しは

git restore --staged <file-path>

(ローカルでの)commitの取消は

git reset HEAD^

でできる。
しかし、git init 直後にはHEADがないし、1つ目のcommitにたいしてHEAD^は存在しないので失敗する。

.gitファイルを削除して再度 git init をすれば、別に何かcommitがあるわけではないのでやり直せるが、コマンドで色々できた方がお得感がある気がする。

stagingの取消

gitの追跡対象から外してやればいい

git rm --cached <file-path>

ファイルがUntrackedの状態に戻る。

git restore --staged はステージングエリアをHEADの状態に復元するコマンド。git rm --cachedはファイルの追跡をやめるコマンド。そのため、新規ファイルを追加した際には両者がほぼ同じ挙動になるらしい。

commitの取消

git update-ref -d HEAD
git reset

HEAD からcommitへの参照を消しているらしい。
これで全てのファイルが未追跡の最初の状態に戻る。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?