Information Technology Reference
In-Depth Information
$ git checkout 7c9bc41
enters the detached HEAD state; even though
7c9bc41
points to the
master
branch.
5-5. Resetting and cleaning a branch
Problem
You are working in a branch—creating, modifying, coping, removing, and renaming
files. After making some changes, you realize that all your modifications (they haven't
been committed yet) are wrong. You want to reset the state of your branch back to the
starting point.
Solution
Clone the repository created in Recipe 5-1 with all the branches:
$ cd git-recipes
$ git clone-with-branches 05-01 05-05
$ cd 05-05
The repository is now clean and you are in the
master
branch. Modify the work-
ing directory using the commands:
$ echo foo > bar.txt
$ echo bar > m1.txt
$ cp m1.txt copy.txt
$ rm m2.txt
$ mv m3.txt new-m3.txt
The
$ git status -sb
now prints:
## master
M m1.txt
D m2.txt