Can anyone clarify some things things for me. If I go back a previous commit using
git checkout HASH
- Running
git branchshows(no branch). What does this mean? - 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?
- 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.
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.
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.
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.