Understanding Git Stashes

Stash is something stored or hidden away for later use.
Why would i want to use git stash in the first place.

let’s say i’m working on the sign up button for a client but he needs work done on the login feature immediately regardless of the urgency f…


This content originally appeared on DEV Community and was authored by Debugging Rabbit

Stash is something stored or hidden away for later use.
Why would i want to use git stash in the first place.

let's say i'm working on the sign up button for a client but he needs work done on the login feature immediately regardless of the urgency for the signup feature, i can quickly stash my signup as work in progress [saving it for some moments before i get back] and start working on the login feature.

Git stashing is keeping files [save files] that you are not ready to use yet [not ready to commit].

Save a stash

git stash

save a stash with a name (recommended)

git stash save wip_login_feature

List Your Stashes

git stash list

This will show you a list of all your stashed changes, with their corresponding stash IDs. For example:

stash@{0}: On master: readme_work
stash@{1}: On master: index_html_in_progress 
stash@{2}: WIP on master: 049d078_Create_index_file

Applying a Specific Stash
To apply a specific stash, you can use the git stash apply command and provide the stash ID as an argument:

git stash apply stash@{1}

This will apply the changes from the stash with ID stash@{1}, which in the example above is the "index_html_in_progress" stash.

Popping a Specific Stash
Alternatively, you can use the git stash pop command to apply and then remove a specific stash not needed again:

git stash pop stash@{0}

This will apply the changes from the most recent stash (stash@{0}) and then remove it from the stash list.

Dropping a Specific Stash
If you no longer need a particular stash, you can remove it from the stash list using the git stash drop command:

git stash drop stash@{2}

This will remove the stash with ID stash@{2} from the list of stashes.


This content originally appeared on DEV Community and was authored by Debugging Rabbit


Print Share Comment Cite Upload Translate Updates
APA

Debugging Rabbit | Sciencx (2024-07-09T00:27:42+00:00) Understanding Git Stashes. Retrieved from https://www.scien.cx/2024/07/09/understanding-git-stashes/

MLA
" » Understanding Git Stashes." Debugging Rabbit | Sciencx - Tuesday July 9, 2024, https://www.scien.cx/2024/07/09/understanding-git-stashes/
HARVARD
Debugging Rabbit | Sciencx Tuesday July 9, 2024 » Understanding Git Stashes., viewed ,<https://www.scien.cx/2024/07/09/understanding-git-stashes/>
VANCOUVER
Debugging Rabbit | Sciencx - » Understanding Git Stashes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/09/understanding-git-stashes/
CHICAGO
" » Understanding Git Stashes." Debugging Rabbit | Sciencx - Accessed . https://www.scien.cx/2024/07/09/understanding-git-stashes/
IEEE
" » Understanding Git Stashes." Debugging Rabbit | Sciencx [Online]. Available: https://www.scien.cx/2024/07/09/understanding-git-stashes/. [Accessed: ]
rf:citation
» Understanding Git Stashes | Debugging Rabbit | Sciencx | https://www.scien.cx/2024/07/09/understanding-git-stashes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.