Git stash commands #2
In my last post, I showed some of the ways to save the current state of working area so that I can hop into other business. Most of my time, I use git stash to juggle different features / issue fix and later come back to finish up my story. There are times where I had to stash more than once. When I want to see all of my stashed list, there is an easy command that I can execute on my terminal.
$ git stash list
The command list all the stashed list as follows:
stash@{0}: WIP on <branch_name>: <hash> <commit message>
stash@{1}: WIP on <branch_name>: <hash> <commit message>
stash@{2}: WIP on <branch_name>: <hash> <commit message>
If I have to view the stashed content, then there is a command to view the changes
$ git stash show
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
If I want to see the diff view between the stashed state and its original parent, then I can append -p
parameter to the git stash show
command. If I have to look over the changes over 2nd stash element (stash@{2}), then following command would be helpful
$ git stash show -p stash@{2}
On my local machine, I had following error with my shell
fatal: ambiguous argument 'stash@2': unknown revision or path not in the working tree.
To work around this issue with my current shell, I had to do
$ git stash show -p stash@"{2}"
Lets suppose, I solved my mystery bug on the production, and now I want continue from where I left off. After looking over the stashed content using above command, I want to get the content on my current working branch. Most of the time, I only use the recent stashed content ( zeroth element). For that, I can do
$ git stash pop
But, sometime, I have to extract some arbitrary content (2nd element)from the stash. Just like on the git show
command, I can do
$ git stash pop stash@"{2}"
If anybody wants to know more, they can go to git stash reference guide.