0

I am working through the git immersion tutorial. We are up to checking out a branch. The instructions say to type the following

$ git checkout <hash>

$ cat hello.rb

It says that the command depends on the has values in the repo and my hash values will be different than theirs so I'm supposed to substitute the proper hash value for my repo. How do I know what to substitute for my hash value? They're using some long number but I don't see a number on my screen at all?

In addition I'm a little lost in the tutorial what exactly are they having me do? I've done other tutorials and they've told me to use get checkout master, so is this different?

Thanks for any context on this in general as well as what I need to do to get to this hash. I wanted to add an screen capture image to help clarify, but I'm new so it wouldn't let me. I'll copy the text hopefully that help...

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

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 9416416... First Commit
$ cat hello.rb
puts "Hello, World"
Zoe
  • 27,060
  • 21
  • 118
  • 148
pgee
  • 49
  • 1
  • 7

2 Answers2

1

I'm assuming you are on this step: http://gitimmersion.com/lab_12.html?

If you followed the previous few pages, they tell you to set up git alias to make typing it easier, but that is optional.

To find your hash, which is the unique ID for the commit, type git log. Note the chronological order and copy and paste the 40-alphanumeric value after the word commit. This is your hash for that particular commit.

The point of these instructions is to show you that you can 'rollback' or see the history of hello.rb's contents by selecting a different hash of the commit and checking it out by typing git checkout <hash>. When you type cat hello.rb, you are outputting the contents of that hello.rb file.

You can either checkout a commit (by copy+pasting in that hash value or even the first few alphanumeric characters of that hash) or a branch, which is what other tutorials will say "git checkout master".

EDIT: Your git hash will not match the author's or the tutorial's hash since its a unique id for your own commit unique to you as the author and unique to the time stamp when you committed.

jojo
  • 1,135
  • 1
  • 15
  • 35
  • 1
    Yes that is the correct stage. I didn't do the list of alias because there were some warnings that there can be conflicts and since I'm new I din't want to mess with it. I do see the really long letter/number string it says commit 116cb22db109f5f260f6891955d74645554990ec. I didn't realize it could be that long, their example was so simple I guess I didn't correlate the two. Thanks for the help. And your context of the 'rollback' is super helpful. Much appreciated. I think I understand a bit better now. – pgee May 07 '15 at 02:36
1

What the tutorial is having you do is check out a specific point in your repo's history. They are demonstrating that you can go back in time and set your project's contents to that state.

Git denominates each commit by a SHA. In your example of showing what you did that is the 9416416. If you do git log you will see a long string of numbers and letters associated with each commit. This is the hash that the tutorial is talking about. Yours will be different from the tutorial because git uses the date and author string in calculating the hash.

Because of the psuedo-random nature of the hash, you really only need the first 6 - 8 characters of the hash for git to determine which one you were talking about without any ambiguity.

The other tutorials told you to git checkout master, what this does is change your repo's state to the latest commit in the master branch. The difference being is that checking out a hash changes things to a specific point in the history. Doing this means that you are not on any branch (the commit that you checked out could be part of the history of any number of branches). So git lets you know that with the message You are in 'detached HEAD' state. This is to remind you that you are not on a branch and could end up with commits that are not on a branch and would be lost.

Schleis
  • 41,516
  • 7
  • 68
  • 87
  • Thank you that is really helpful. I think I'm understanding it all a bit better now (but I still have a ways to go....clearly) but thanks for helping me on my way :) – pgee May 07 '15 at 02:38