0

I have a local git repository with only the main branch. So I did a few commits. Afterward, I decided to go back to the first commit. So I did

git checkout xxxxxx

But now when I do git log I can only see the first commit. How do I get back to the latest code?

lang2
  • 11,433
  • 18
  • 83
  • 133
  • http://stackoverflow.com/q/17995608/520162 could be quite relevant here. – eckes Mar 02 '15 at 14:57
  • `git checkout master`? – Mikolaj Mar 02 '15 at 14:57
  • Use this command carefully. The git checkout command deletes the unstaged and uncommitted changes of tracked files in the working tree and it is not possible to restore this deletion via Git. – gpullen Mar 02 '15 at 15:22
  • 1
    @gpullen: This is wrong. `git checkout` does **not** delete anything unstaged or overrides uncommitted changes. This is what `git reset` does. And yes, you have to be careful when doing a `git reset --hard`. But this is not the case for `git checkout`. `checkout` is safe! – eckes Mar 02 '15 at 15:44
  • Ok...so git checkout filename would replace with the latest version from the current branch and the changes will be discarded - no backup is kept – gpullen Mar 02 '15 at 16:07

1 Answers1

1

To get back to the last branch you checked out:

git checkout -

Generally speaking:

git checkout <BRANCH-NAME> 

checks out that branch.

eckes
  • 64,417
  • 29
  • 168
  • 201