Information Technology Reference
In-Depth Information
• When you commit the new revision goes to the current branch. The file
.git/HEAD doesn't change. The SHA-1 of the newly created revision
will be stored in the .git/refs/heads/branch-name file. If the
branch was already stored in a packed format, the format is changed to
loose.
• When you create a new branch with $ git branch branch-
name a new file .git/refs/heads/branch-name is created and
it stores the SHA-1 of the revision passed as a parameter to the $ git
branch command or the current revision. The file .git/HEAD remains
unchanged. The format for a new branch is always loose.
• When you switch branches with the $ git checkout branch-
name command, all the files in .git/refs/heads remain unchanged.
The symbolic reference to the branch branch-name is stored in .git/
HEAD . It has the form ref: refs/heads/branch-name . The com-
mand resets the working directory to the state conforming to the latest
revision in branch-name branch. The command doesn't change the
format for storing a branch tip.
As you have learned in the Solution section of Recipe 5-1, both operations, creating
and switching to a new branch, can be achieved with one command:
$ git checkout -b new-branch existing-branch
This command creates a new branch named new-branch that points to the same
revision as an existing branch named existing-branch .
The HEAD plays a very special role in many git commands. Everywhere you need
the SHA-1 of the revision that you are currently working on, you can use HEAD in-
stead. Moreover, HEAD is usually a default value used for absent parameters. The com-
mands:
$ git reset --hard
$ git reset --hard HEAD
are identical. In a similar fashion, you can create a new branch with:
$ git branch new-name [REVISION]
Search WWH ::




Custom Search