Download Scott Chacon

Transcript
154
CH APT ER 6 N G IT TOOL S
Stashing Your Work
To demonstrate, you’ll go into your project and start working on a couple of files and possibly
stage one of the changes. If you run cepop]pqo, you can see your dirty state:
cepop]pqo
Kj^n]j_di]opan
?d]jcaopk^a_kiieppa`6
$qoacepnaoapDA=@8beha:***pkqjop]ca%
ik`ebea`6ej`at*dpih
?d]jca`^qpjkpql`]pa`6
$qoacep]``8beha:***pkql`]pasd]psehh^a_kiieppa`%
ik`ebea`6he^+oeilhacep*n^
Now you want to switch branches, but you don’t want to commit what you’ve been working on yet; so you’ll stash the changes. To push a new stash onto your stack, run cepop]od:
cepop]od
O]ra`skngejc`ena_pknu]j`ej`atop]paX
SELkji]opan6,05`,34]``a`pdaej`atbeha
DA=@eojks]p,05`,34]``a`pdaej`atbeha
$Pknaopknapdaipulacepop]od]llhu%
Your working directory is clean:
cepop]pqo
Kj^n]j_di]opan
jkpdejcpk_kiiep$skngejc`ena_pknu_ha]j%
At this point, you can easily switch branches and do work elsewhere; your changes are
stored on your stack. To see which stashes you’ve stored, you can use cepop]odheop:
cepop]odheop
op]od<w,y6SELkji]opan6,05`,34]``a`pdaej`atbeha
op]od<w-y6SELkji]opan6_.20,1-***Naranp]``a`beha[oeva
op]od<w.y6SELkji]opan6.-`4,]1***]``a`jqi^anpkhkc
In this case, two stashes were done previously, so you have access to three different
stashed works. You can reapply the one you just stashed by using the command shown in
the help output of the original op]od command: cepop]od]llhu. If you want to apply one of
the older stashes, you can specify it by naming it, like this: cepop]od]llhuop]od<w.y. If you
don’t specify a stash, Git assumes the most recent stash and tries to apply it: