From Changes to Safe Keeping: Git Stash

✦ You’re working on a feature but need to switch branches without losing your work.
✦ You want to save your unfinished work temporarily to a separate place without committing it to your feature branch.

That’s where git stash helps! It lets you store y…


This content originally appeared on DEV Community and was authored by Farhat Sharif

✦ You’re working on a feature but need to switch branches without losing your work.
✦ You want to save your unfinished work temporarily to a separate place without committing it to your feature branch.

That’s where git stash helps! It lets you store your current changes and gives you a clean working directory, so you can switch tasks without losing any progress.

1. Stash changes:

Command: git stash
Description: Saves your local changes to a separate place and reverts your working directory to the last commit, allowing you to switch branches or work on something else.
Command: git stash push -m "stash message"
Store changes with message. Add a descriptive message so you can identify the work stored in the stash easily.

2. List saved stashes:

Command: git stash list
Description: Shows you a list of saved stashes which you can utilize again.

3. View Stashed Changes:

Command: git stash show stash@{n}
Description: View the changes stored in a specific stash. Stash are referenced by numbers. e.g. stash@{1}

4. Apply a specific stash:

To restore stashed changes you have two options:
a).
Command: git stash apply stash@{n} 
Description: Apply the changes and leave a copy in the stash.

b).
Command: git stash pop stash@{n} 
Description: Apply the changes and delete these changes from the stash.

If you don't use stash reference, you are working with the latest stash:
git stash apply
git stash pop


With git stash, you can save, view, and restore changes whenever needed. Perfect for switching tasks!


This content originally appeared on DEV Community and was authored by Farhat Sharif


Print Share Comment Cite Upload Translate Updates
APA

Farhat Sharif | Sciencx (2024-09-25T22:16:47+00:00) From Changes to Safe Keeping: Git Stash. Retrieved from https://www.scien.cx/2024/09/25/from-changes-to-safe-keeping-git-stash/

MLA
" » From Changes to Safe Keeping: Git Stash." Farhat Sharif | Sciencx - Wednesday September 25, 2024, https://www.scien.cx/2024/09/25/from-changes-to-safe-keeping-git-stash/
HARVARD
Farhat Sharif | Sciencx Wednesday September 25, 2024 » From Changes to Safe Keeping: Git Stash., viewed ,<https://www.scien.cx/2024/09/25/from-changes-to-safe-keeping-git-stash/>
VANCOUVER
Farhat Sharif | Sciencx - » From Changes to Safe Keeping: Git Stash. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/25/from-changes-to-safe-keeping-git-stash/
CHICAGO
" » From Changes to Safe Keeping: Git Stash." Farhat Sharif | Sciencx - Accessed . https://www.scien.cx/2024/09/25/from-changes-to-safe-keeping-git-stash/
IEEE
" » From Changes to Safe Keeping: Git Stash." Farhat Sharif | Sciencx [Online]. Available: https://www.scien.cx/2024/09/25/from-changes-to-safe-keeping-git-stash/. [Accessed: ]
rf:citation
» From Changes to Safe Keeping: Git Stash | Farhat Sharif | Sciencx | https://www.scien.cx/2024/09/25/from-changes-to-safe-keeping-git-stash/ |

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.