tags:

views:

31

answers:

2

I have recently moved from SVN to Git and am a bit confused about something. I needed to run the previous version of a script through a debugger, so I did git checkout <previous version hash> and did what I needed to do.

Now I want to get back to the newest version, but I don't know the hash for it. When I type git log, I don't see it.

How can I do this? Also, is there an easier way to change versions than by typing out hashes - something like "go back two versions" or "go to the most chronologically recent"?

+2  A: 

git checkout master should do the trick. To go back two versions, you could say something like git checkout HEAD~2, but better to create a temporary branch based on that time, so git checkout -b temp_branch HEAD~2

Paul Betts
Cool! `git checkout master` is exactly how I switch back from a branch. So does that mean that when I check out a previous version, I'm essentially creating a branch?
Nathan Long
@Nathan: In git a branch is really mostly a movable pointer to a certain revision. So conceptually, you're sort of creating a branch, but not in the sense that git thinks of branches.
DLH
So in the simplest case, where I've got a bunch of linear changes, when I checkout an earlier revision, I'm moving the HEAD pointer there, which means `git log` will display relative to that point? And when I checkout master, I move the pointer to the latest version of the master branch?
Nathan Long
@Nathan: Exactly. HEAD is something called a symbolic ref - it's in general a pointer to another ref (the currently checked out branch). `git checkout` is a way to move HEAD around. When you detached HEAD, you made it point straight to that given commit; when you check out master again it points back to master. (And many many commands like `git log` actually take a revision range, which defaults to HEAD.)
Jefromi
+1  A: 

You can check out using branch names, for one thing.

I know there are several ways to move the HEAD around, but I'll leave it to a git expert to enumerate them.

I just wanted to suggest gitk --all -- I found it enormously helpful when starting with git.

Jay
+1 for `gitk --all`. **SO** useful.
DLH