HEAD ORIG_HEAD他

symref - シンボリック参照

  • HEAD
  • ORIG_HEAD
  • FETCH_HEAD
  • MERGE_HEAD

HEAD

$ cat .git/HEAD               (1) 
ref: refs/heads/master

$ cat .git/refs/heads/master  (2) 
abc1234a8cb02bb47d9901ba2
  • (1) .git/HEADはカレントブランチのref(ここではmasterブランチであり、その実態は.git/refs/heads/masterというファイル)を参照している
  • (2) 次に.git/refs/heads/masterはコミットID abc123を参照している
  • すなわち、ここではHEADとmasterブランチとabc123は同じであり、git reset abc123git reset mastergit reset HEADは同じ結果になるる

ORIG_HEAD

$ git log --oneline                (1)
abc1234 (HEAD, master) message2
def7890 message1

$ ls .git/ | grep HEAD             (2)
HEAD

$ git reset HEAD^                  (3)
$ ls .git/ | grep HEAD
HEAD
ORIG_HEAD
$ cat .git/ORIG_HEAD
abc1234...

$ git co ORIG_HEAD                 (4)
  • (1) 2つコミットがある状態で、最新がabc1234、その前がdef7890とする
  • (2) 最初はORIG_HEADファイルは存在しない
  • (3) git resetを実行して始めてORIG_HEADが作成される
    • git reset HEAD^は一般的には最新のコミットを削除して1つ前に戻る意図で使われるコマンドであり、下で言うHEADをdrasticにmoveしてることに相当するから
    • なお、git reset HEAD^以外にgit merge masterでもORIG_FILEができる。git checkout HEAD^ではORIG_HEADはできない
  • (4) 上の(3)の時点で(事前にabc1234というコミットIDをメモしておかない限り)コミットabc1234は到達不能であるが、ORIG_HEADをを指定すれば到達することができる

    ORIG_HEAD is created by commands that move your HEAD in a drastic way, to record the position of the HEAD before their operation, so that you can easily change the tip of the branch back to the state before you ran them. https://git-scm.com/docs/gitrevisions

参考

https://stackoverflow.com/questions/964876/head-and-orig-head-in-git


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

Last-modified: 2021-05-05 (水) 03:30:44