GIT Practical Reference
GIT Practical Reference
Stash Changes Temporarily
In Git, you can temporarily stash (save) changes, so you can switch branches or work on a different task without committing your current changes.
Stash All Changes
To stash all your changes both staged and unstaged (not including new untracked files), simply run:
git stash
This command will save your current changes and revert your working directory to the state of the last commit.
To stash all your changes both staged and unstaged (including new untracked files) run:
git stash -u
Stash Specific Changes
You can also stash specific changes by specifying the files or hunks you want to stash. For example, to stash changes in a specific file:
git stash push -m "Description of changes" <file_name>
View Stashes List
To view a list of your stashes, use the following command:
git stash list
This will display a list of all your stashes, each with a unique identifier.
Apply a Stash
When you're ready to work again on the stashed changes you can bring the changes back.
To apply a specific stash from the list, use the following command:
git stash apply stash@{<stash_number>}
Replace <stash_number>
with the number corresponding to the stash you want to apply.
If you want to apply a stash and remove it from the stash list in one step, you can use the pop
option:
git stash pop stash@{<stash_number>}
This will apply the stash and remove it from the list.