Tutorial by Examples

When working on a project, you might be half-way through a feature branch change when a bug is raised against master. You're not ready to commit your code, but you also don't want to lose your changes. This is where git stash comes in handy. Run git status on a branch to show your uncommitted chang...
Save the current state of working directory and the index (also known as the staging area) in a stack of stashes. git stash To include all untracked files in the stash use the --include-untracked or -u flags. git stash --include-untracked To include a message with your stash to make it more ...
git stash list This will list all stashes in the stack in reverse chronological order. You will get a list that looks something like this: stash@{0}: WIP on master: 67a4e01 Merge tests into develop stash@{1}: WIP on master: 70f0d95 Add user role to localStorage on user login You can refer t...
Shows the changes saved in the last stash git stash show Or a specific stash git stash show stash@{n} To show content of the changes saved for the specific stash git stash show -p stash@{n}
Remove all stash git stash clear Removes the last stash git stash drop Or a specific stash git stash drop stash@{n}
To apply the last stash and remove it from the stack - type: git stash pop To apply specific stash and remove it from the stack - type: git stash pop stash@{n}
Applies the last stash without removing it from the stack git stash apply Or a specific stash git stash apply stash@{n}
To get your most recent stash after running git stash, use git stash apply To see a list of your stashes, use git stash list You will get a list that looks something like this stash@{0}: WIP on master: 67a4e01 Merge tests into develop stash@{1}: WIP on master: 70f0d95 Add user role to lo...
If you would like to stash only some diffs in your working set, you can use a partial stash. git stash -p And then interactively select which hunks to stash. As of version 2.13.0 you can also avoid the interactive mode and create a partial stash with a pathspec using the new push keyword. git ...
You've made a stash and wish to checkout only some of the files in that stash. git checkout stash@{0} -- myfile.txt
Stashing takes the dirty state of your working directory – that is, your modified tracked files and staged changes – and saves it on a stack of unfinished changes that you can reapply at any time. Stashing only modified files: Suppose you don't want to stash the staged files and only stash the mod...
If while working you realize you're on wrong branch and you haven't created any commits yet, you can easily move your work to correct branch using stashing: git stash git checkout correct-branch git stash pop Remember git stash pop will apply the last stash and delete it from the stash list. T...
If you have only just popped it and the terminal is still open, you will still have the hash value printed by git stash pop on screen: $ git stash pop [...] Dropped refs/stash@{0} (2ca03e22256be97f9e40f08e6d6773c7d41dbfd1) (Note that git stash drop also produces the same line.) Otherwise, you...

Page 1 of 1