Information Technology Reference
In-Depth Information
$ cd git-recipes
$ git clone-with-branches 05-01 05-07
$ cd 05-07
Switch to the info branch and modify the working directory with the following
commands:
$ git checkout info
$ echo foo > i1.txt
The i1.txt file was modified and it is listed as:
_M i1.txt
by $ git status -sb . This file is not present in the master branch. If you
now execute the command $ git checkout master , you will see the warning:
error:
Your local changes to the following files
would be overwritten by checkout:
i1.txt
Thus, git refuses to the switch to the current branch to the master because you
would lose your changes to the i1.txt file.
Assume that your modifications are important—you want to preserve and commit
them in master branch. There are three different approaches you may take:
• You can stash your changes for a while, change a branch, and then retrieve
the changes. This is what we will do in this recipe.
• You can merge your changes with a branch you switched to during check-
out. This solution is similar to stashing.
• Finally,youcancommit inthecurrent(wrong)branchandthenmoveyour
revision to appropriate branch. This procedure will be discussed in Recipe
5-8.
Stashing uncommitted changes
Search WWH ::




Custom Search