LoginSignup
18
15

More than 5 years have passed since last update.

GitのHEADを理解する

Posted at

rebaseを取り消す際にHEADではなくORIG_HEADを指定することを理解せずにやっていましたが、HEADも実はよく分かっていないことに気づいたので、調べることにしました。

公式ドキュメントの少し分かりにくいことろにきちんと載っていました。

5つのHEAD

以下の英文はgitrevisionsから引用しています。

HEAD

ワーキングツリーの最新のコミット

HEAD names the commit on which you based the changes in the working tree.

FETCH_HEAD

最後にフェッチを行ったブランチを(記録)

FETCH_HEAD records the branch which you fetched from a remote repository with your last git fetch invocation.

ORIG_HEAD

HEADが移動するコマンドを叩いた際に、コマンド実行時の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.

MERGE_HEAD

マージの際に、ブランチに統合されたコミット(群)を記録

MERGE_HEAD records the commit(s) which you are merging into your branch when you run git merge.

CHERRY_PICK_HEAD

チェリーピックの際に、ブランチに統合されたコミットを記録

CHERRY_PICK_HEAD records the commit which you are cherry-picking when you run git cherry-pick.

HEADは一時的なコミット(群)の記録

gitはよく図形的に説明されるのでHEADを位置と説明されますが、FETCH_HEADやMERGE_HEADの説明からわかるようにHEADは位置を表すわけではないようです。ただ大抵の場合HEADやORIG_HEADしか意識されないので、結局のところ「HEADはコミットの位置」という解釈でよい気がします。

謝辞

最後まで読んでいただき、誠にありがとうございます。

18
15
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
18
15