Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout of commit# is taking me to a different commit#

Tags:

git

So, something weird that I hadn't encountered before.

$ git checkout fb4b6581d36a522e092491d1dc5f49cb96ab7a3e
Note: checking out 'fb4b6581d36a522e092491d1dc5f49cb96ab7a3e'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 8a74070...

Basically my question is, if I checked out fb4b6581, why is HEAD now at 8a74070? My basic Git knowledge is not enough to fully understand what's going on. Let me know if I should add more information to this question, this is the gist of the issue I'm seeing.

Also, note that if I do git log, I do not see fb4b6581 anywhere, but I do see 8a74070, which adds to my confusion.

Thank you

like image 908
So Many Goblins Avatar asked Aug 04 '17 16:08

So Many Goblins


People also ask

Can you git checkout a commit?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.

What does it mean to checkout a commit in git?

The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.

What is check out commit?

In Git, "checking out" means making a certain state your current working state: the actual files in your Working Copy will be the ones from that exact point in time.


1 Answers

This means that the Git object with ID fb4b6581d36a522e092491d1dc5f49cb96ab7a3e is a tag object (an annotated tag).

You can see it with:

$ git cat-file -t fb4b6581d36a522e092491d1dc5f49cb96ab7a3e

which will print the object's type, and:

$ git cat-file -p fb4b6581d36a522e092491d1dc5f49cb96ab7a3e

which will print the raw tag contents directly. The git show command will show the tag's contents first, and then the commit to which the tag points, which is this other object 8a74070....

like image 138
torek Avatar answered Sep 19 '22 11:09

torek