Git stash: Difference between revisions
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
=Overview= | =Overview= | ||
Stash the changes in a dirty working directory away. The command saves the local modifications away and reverts the working directory to match the HEAD commit. | Stash the changes in a dirty working directory away. The command saves the local modifications away and reverts the working directory to match the HEAD commit. The modifications are saved in bulk, it is not possible to choose individual files. | ||
To stash away changes: | To stash away changes: | ||
<syntaxhighlight lang='bash'> | |||
git stash | |||
Saved working directory and index state WIP on ''branch-name'': 0d0178916ee ''commit comment'' | |||
</syntaxhighlight> | |||
The modifications stashed away can be listed with: | The modifications stashed away can be listed with: | ||
<syntaxhighlight lang='bash'> | |||
git stash list | |||
</syntaxhighlight> | |||
To see the files affected by the stash: | To see the files affected by the stash: | ||
<syntaxhighlight lang='bash'> | |||
git stash show | |||
</syntaxhighlight> | |||
They can be restored, potentially in top of a different commit, with: | |||
<syntaxhighlight lang='bash'> | |||
git stash apply | |||
</syntaxhighlight> | |||
Without an argument, "apply" applies the content set at the top of the stack (the latest). | |||
Note that the stash state stays on the stack. To achieve the same effect - apply the modification and remove it from stack, use "pop" instead of "apply": | |||
<syntaxhighlight lang='bash'> | |||
git stash pop | |||
</syntaxhighlight> | |||
Also, the change can be explicitly removed if "apply" was used: | |||
<syntaxhighlight lang='bash'> | |||
git stash drop | |||
</syntaxhighlight> | |||
To remove an arbitrary stash state: | |||
<syntaxhighlight lang='bash'> | |||
git stash drop <number> | |||
</syntaxhighlight> | |||
This clears all stash entries: | |||
<syntaxhighlight lang='bash'> | |||
git stash clear | |||
</syntaxhighlight> |
Latest revision as of 06:39, 22 October 2020
Internal
Overview
Stash the changes in a dirty working directory away. The command saves the local modifications away and reverts the working directory to match the HEAD commit. The modifications are saved in bulk, it is not possible to choose individual files.
To stash away changes:
git stash
Saved working directory and index state WIP on ''branch-name'': 0d0178916ee ''commit comment''
The modifications stashed away can be listed with:
git stash list
To see the files affected by the stash:
git stash show
They can be restored, potentially in top of a different commit, with:
git stash apply
Without an argument, "apply" applies the content set at the top of the stack (the latest).
Note that the stash state stays on the stack. To achieve the same effect - apply the modification and remove it from stack, use "pop" instead of "apply":
git stash pop
Also, the change can be explicitly removed if "apply" was used:
git stash drop
To remove an arbitrary stash state:
git stash drop <number>
This clears all stash entries:
git stash clear