0% found this document useful (0 votes)
18 views20 pages

Stashing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views20 pages

Stashing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

GIT STASH

INT 331
MEANING
Git stashing. Stash means to store (changes)
safely in a hidden place (the stash stack).

Git has an area called the stash where you


can temporarily store a snapshot of your
changes without committing them to the
repository. It’s separate from the working
directory, the staging area, or the
repository.
PURPOSE

• This functionality is useful when you’ve


made changes to a branch that you aren’t
ready to commit, but you need to switch to
another branch.
Stash Changes
• To save your changes in the stash, run the
command:
git stash save "optional message for
yourself“
• This saves your changes and reverts the
working directory to what it looked like for the
latest commit. Stashed changes are available
from any branch in that repository.

• Note that changes you want to stash need to


be on tracked files. If you created a new file
and try to stash your changes, you may get the
error No local changes to save.
View Stashed Changes
• To see what is in your stash, run the command:
git stash list
This returns a list of your saved snapshots in the
format
stash@{0}: BRANCH-STASHED-CHANGES-ARE-FOR:
MESSAGE.
The stash@{0} part is the name of the stash,
and the number in the curly braces ({ }) is the
index of that stash.

If you have multiple change sets stashed, each


one will have a different index.
The latest stashes (stash@{0}) will be at
the top of the stack.
The older stashes (stash@{1}) will be at
the bottom of the stack.
Understanding the format of stash

• Stash@{0} – this is just a stash reference.


• It refers to the particular stash.

• By default, Stash@{0} is always the latest


stash.

• Note: Higher numbered stashes like


stash@{3} are older stashes. The latest
stashes always have the lowest number.
• WIP On Login-Page – Login-Page is just
a branch name like any other branch and

• WIP stands for Work In Progress. "WIP on


Login-Page " means that stash@{0} was
created on the branch "fake".
2e4f87a is a Commit hash and override
some stuffs is a commit message. At
that time of stash creation, 2e4f87a
override some stuffs is the latest
commit.
How to show the latest stash

• Maybe you have multiple stashes in your


stash stack and you're not able to tell
which stash reference holds which changes.
• So, before you apply stashes on the current
working branch, you can confirm and show
the changes recorded in the stash with the
below command:
git stash show
• If you want to show the recorded changes
of the latest stash on patch view, use
the -p flag at the end of the command, like
this:
git stash show –p
For untracked files

If you also want to show untracked files, use the -u flag.

git stash show -u


You can show untracked files with the patch
format:

git stash show -p -u


How to show an individual stash

• You can show the recorded changes of an


individual stash by using stash reference.

git stash show stash@{1}


For the patch format, you guessed it right –
use the -p flag.
• git stash show stash@{1} -p
• Want to show a stash with untracked files?
Use this command:
git stash show stash@{1} -u or this one:
git stash show stash@{1}
--include-untracked
• Whereas you can do this to show untracked
files only:
git stash show stash@{1}
--only-untracked
How to apply the stash
You can also apply the latest stash without
removing the stash from the stash stack
like this:
git stash apply
You can apply an earlier stash by using the
stash reference:

git stash apply stash@{3}


To apply the recorded changes of your latest
stash on the current working branch as well
as remove that stash from the stash stack,
run this command:

git stash pop


How to delete a stash
Want to clear all the stashes from stash
stack? Use this command:
git stash clear

Want to delete a particular stash?

Yes! you are right – you use the stash


reference:
git stash drop stash@{2}
How to create a branch from stash

You can create a new branch from your latest


stash. Just use this command:

• git stash branch <branch_name>


If you want to create a branch from an
earlier stash, that's also possible by using
stash reference:

git stash branch <branch_name> stash@{revision}

• E.g ,
git stash branch purple stash@{3}

You might also like