How to work with
Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.
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.
Now you want to switch branches, but you don’t want to commit what you’ve been working on yet, to stash your modified files in your project use
Now your working directory should be clean:
To list all your stashes use
Now if you want to apply the most recent stashed files:
In order to remove a
These are some general, most useful commands to work with
#git #stash #stash_apply #stash_list #stash_drop #stash_save
stash
in git
?Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.
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.
Now you want to switch branches, but you don’t want to commit what you’ve been working on yet, to stash your modified files in your project use
git stash
:$ git stash
Saved working directory and index state \
"WIP on master: 049d078 added the index file"
HEAD is now at 049d078 added the index file
(To restore them type "git stash apply")
Now your working directory should be clean:
$ git status
# On branch master
nothing to commit, working directory clean
To list all your stashes use
git stash list
:$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
Now if you want to apply the most recent stashed files:
$ git stash apply
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
#
# modified: index.html
# modified: lib/simplegit.rb
In order to remove a
stash
, use git stash drop YOUR_STASH
:$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
$ git stash drop stash@{0}
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)
These are some general, most useful commands to work with
stash
. Enjoy the article :)#git #stash #stash_apply #stash_list #stash_drop #stash_save