4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Git】git resetまとめ

Posted at

#基本的な考え方

$ git reset <where?> <when?>

#git reset 第1オプション

どこの環境を戻すのか指定する

環境 戻す範囲の指定オプション 今の環境を次に移動させるコマンド
ワーキングツリー --hard git add
インデックス環境 --mixed git commit
HEAD --soft
#影響範囲は、一連のadd~commit(ワーキングツリー, インデックス, HEAD)
$ git reset --hard <when?>

# 影響範囲は、add後~commit(インデックス, HEAD)
$ git reset --mixed <when?>

# 影響範囲は、commit後のみ(HEAD)
$ git reset --soft <when?>

#git reset 第2オプション

どのくらい前に戻すのか

# コミット履歴
$ git log

# HEADの履歴
$ git reflog

9f12f80 (HEAD -> master, origin/master, fix-home-iichan) HEAD@{0}: checkout: moving from fix-home-iichan to master
9f12f80 (HEAD -> master, origin/master, fix-home-iichan) HEAD@{1}: reset: moving to HEAD@{8}
9f12f80 (HEAD -> master, origin/master, fix-home-iichan) HEAD@{2}: checkout: moving from master to fix-home-iichan
9f12f80 (HEAD -> master, origin/master, fix-home-iichan) HEAD@{3}: checkout: moving from master to master
# 一連のadd~commitを、直前の状態に戻す
$ git reset --hard HEAD^

# 一連のadd~commitを、3つ前の状態に戻す
$ git reset --hard HEAD@{2}

# 動作確認後、一連のadd~commitを、最新の状態に戻す
$ git reset --hard ORIG_HEAD
4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?