2

Can anyone clarify some things things for me. If I go back a previous commit using

git checkout HASH
  1. Running git branch shows (no branch). What does this mean?
  2. If I edit a file then commit. Will it create a new branch or will it simply update the entire branch so when I go back to the current commit the file will also be updated?
  3. Related to #2, is the purpose of checking out a previous commit so you can make a branch out of it or something more? I'm guessing something more but I can't see it since my project isn't all that complex.
Zoe
  • 27,060
  • 21
  • 118
  • 148
enchance
  • 29,075
  • 35
  • 87
  • 127

2 Answers2

1
  1. It means you have a detached HEAD ref pointing at the commit you checked out. This means any commits going ahead will not be associated with a branch and will only be accessible by commit SHA once you move HEAD off the detached tree.

  2. No branch is created or updated. You will create a commit tree that starts at your checked out commit, however it isn't part of any branch until you tell git to make this tree part of a branch.

  3. It is intended to do manipulations on that commit that you may not wish to make a part of any branch in your repository. This could be for throw-away work. You could always make a new branch from a previous commit should you wish to do so.

git-checkout man page provides a good explanation of these issues and would clarify your understanding of checkout being used in these various ways.

jmlane
  • 2,109
  • 1
  • 16
  • 24
0
  1. It means you are in a DETACHED HEAD mode
  2. No, your commit isn't referenced by any branch: no HEAD of any branch referenced your new commit (hence the "detached head" part).
    See also "HEAD and ORIG_HEAD in Git"
  3. git checkout -b aNewBranch is enough to create a new branch, which will reference your current commit (which will no longer be a "detached HEAD").

enter image description here

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note to self: other references linked in http://www.educatedguesswork.org/2012/01/git_y_u_no.html – VonC Mar 02 '12 at 07:53