git reflog

git

書き方

git reflog [show] [<ref>]

HEADとブランチが通ってきた位置を記録します。reset --hardやブランチ削除で失ったコミットはここで見つかりますが、既定で90日で期限切れになり、この記録は自分の手元にしかありません。

よく使うオプション

オプション意味
show <ref>the positions of one branch instead of HEAD
--date=isoreal timestamps instead of relative ones
-n <n>only the last n entries
HEAD@{n}the commit HEAD pointed at n moves ago
expire --expire=now --allwipe the log, which also gives up the safety net

git reflog

every position HEAD has had, newest first

git reflog --date=iso -n 20

the last twenty moves with real dates

git reset --hard HEAD@{1}

undoes the reset you just regretted

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git reflog は何をしますか。

HEADとブランチが通ってきた位置を記録します。reset --hardやブランチ削除で失ったコミットはここで見つかりますが、既定で90日で期限切れになり、この記録は自分の手元にしかありません。

Q. どう打ちますか。

git reflog [show] [<ref>] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは5個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-reflog