Information Technology Reference
In-Depth Information
After saving your changes, the stash command resets the working directory. The re-
pository becomes clean and its working directory reflects the snapshot of the latest re-
vision in your current branch.
To restore the stashed state, you should use the $ git stash pop command.
You can execute this command in every branch. Popped stashed changes are merged
with your current branch.
Git allows stashing uncommitted changes to be performed an arbitrary number of
times—they are stored on stack. Stashed states can be listed with the $ git stash
list command. It produces an output similar to the one below:
stash@{0}: WIP on info: 0d6501b i3
stash@{1}: WIP on doc: 23d9855 d3
stash@{2}: WIP on master: ae34fcd m4
You also can change the default message WIP on XXX to something more mean-
ingful such as:
$ git stash save A very descriptive information
The command $ git stash is equivalent to $ git stash save WIP on
[branch-name] . You have already learned the meaning of WIP in Recipe 3-2. It
stands for work in progress.
Although $ git stash is a very convenient tool to use for switching branches in
dirty repo, you also can use a forced checkout. There are two switches of the $ git
checkou t command that will help you: -m or -f . The first one merges your changes
with the branch you switch to; the second throws your modifications away.
Hint Stashing can be applied if there are no conflicts, of course. Therefore, in Re-
cipe 5-6 you also can use stashing to save and restore your uncommitted changes.
5-8. Committing in a wrong branch
Problem
Search WWH ::




Custom Search