For example, if you want to see which commit the branch mybranch
references, you can run
$ git rev-parse mybranch
$ cat .git/refs/heads/mybranch
git log
, is there a single file git looks at to find all the commits for that branch?
git log
figures out the history by taking the commit the
branch references and looking at that commit's parent(s) / grandparents
etc. A commit's parents can't change, so the history is always the
same.
HEAD is a reference to the current commit or branch you have
checked out! Usually it's a reference to a branch. You can see what it
is by running cat .git/HEAD
.
"You are in 'detached HEAD' state"
.HEAD
points to a commit, not a branch
when HEAD
points to a commit, no branch gets updated when you make new commits.
git warns you about this because if commits aren't on a branch, it's hard to find them later.
git commit
, does it change which commit your current branch points to?
git commit
creates a new commit and then updates the current branch to point at the new commit.
you can view it with
$ git reflog BRANCHNAME
so if you want to go back to what you had on that branch last Tuesday, you can!
creating a new branch just creates 2 small files: a reference to the current commit and a history of what you've done with the branch (the reflog).
yes!
you can make a branch point at a different commit with either git
reset
or git branch
!
banana
), do both versions of the branch always point at the same commit?
branch names are local to a repository, and they don't get automatically synced in any way.