In this article you will see that what is git stash? and how you can load stashed changes in current branch? and how you see git stash changes with Appling it.
What is git stash?
git stash
is a Git command that allows you to temporarily save changes that you have made in your working directory but have not yet committed. The stash is like a buffer that you can use to store changes while you switch to a different branch, perform another task, or troubleshoot a problem.
When you run git stash
, Git will automatically save the changes in your working directory, including both modified files and untracked files, and restore your working directory to the state it was in when you last committed. The saved changes are stored in the stash, and you can later apply them to your working directory or discard them if you no longer need them.
Here's an example of how to use git stash
:
git stash
to save the changes to the stash.git stash apply
or git stash pop
.
The git stash apply
command will reapply the changes from the stash to your working directory, but keep the stash intact so you can reapply it later if necessary. The git stash pop
command will reapply the changes and also remove the stash.
You can also use the git stash list
command to view a list of all the stashes that you have created, and the git stash show
command to view the contents of a specific stash.
How to review git stashed changes without applying it ?
To view the contents of a stash without applying it, you can use the git stash show
command.
The git stash show
command displays the changes that are stored in a stash, showing you a list of the files that have been modified and the differences between the staged and unstaged versions of those files. By default, git stash show
displays the changes for the latest stash, but you can specify a different stash by providing its stash index.
For example, to view the changes in the latest stash, you can run:
git stash show
To view the changes in a specific stash, you can run:
git stash show stash@{n}
where n is the stash index.
Using git stash show
is a convenient way to review the changes that are stored in a stash before you apply them, giving you a chance to make any necessary modifications before the changes are permanently applied to your working tree.