In Git, you can stash your changes using the git stash command. This command allows you to save your uncommitted changes temporarily, so you can work on something else without losing your progress. Here's how you can do it:
1. Stash Your Changes:
To stash your current changes (both staged and unstaged), run:
git stash
or, if you only want to stash changes that are not staged but keep the staged changes:
git stash push -m "your message" # Use a message to label your stash
This command will save your changes and revert your working directory to match the last committed state.
2. View Stashed Changes:
To see a list of all stashed changes, use:
git stash list
3. Apply Stashed Changes:
To apply the latest stashed changes, run:
git stash apply
If you want to apply a specific stash (e.g., the one labeled as stash@{0}), you can specify it:
git stash apply stash@{0}
4. Pop Stashed Changes:
If you want to apply the stashed changes and remove them from the stash list, you can use:
git stash pop
5. Drop Stashed Changes:
If you want to delete a specific stash without applying it, you can run:
git stash drop stash@{0}
6. Clear All Stashes:
If you want to remove all stashed changes, use:
git stash clear
Stashing is useful when you need to switch branches, pull changes, or perform some other actions without committing your current work.