Information Technology Reference
In-Depth Information
succeeds. All the changes are preserved, and you are now in the doc branch. The
output of $ git status -sb is now almost the same—only the branch name is
changed to doc :
## doc
M m1.txt
D m2.txt
D m3.txt
?? bar.txt
?? new-m3.txt
You still haven't remembered about your changes or about your current branch and
you inadvertently stage all the changes with $ git add -A .
Finally, you realize that your changes are still not committed. Moreover, you would
like them to go to the master branch. To commit your modifications into the mas-
ter branch you have to switch the branch and create the revision:
$ git checkout master
$ git snapshot Recipe 5-5 Switching branches in dirty
repository without conflicts
Your repository is clean and all the modifications are stored in the master branch.
How It Works
In all the recipes up to Recipe 5-5 we switched branches when a repository was clean.
But git allows switching branches even if repository is dirty. By default, all changes are
preserved even if they were staged or not. If git cannot preserve your changes then it
will refuse to switch branches. In other words, switching branches in a dirty repository
is permitted if and only if the changes that are not committed do not collide with the
contents of the branch you are switching to . Remember a simple rule of thumb: if the
branch was switched, it means that your dirty modifications didn't cause any collisions.
However, there is one slight exception: the only situation when you can loose uncom-
mitted changes without any warning during branch switching is when you remove a
file that was not present in the branch you are switching to.
You can verify it with the following commands:
Search WWH ::




Custom Search