git stash


git stash can be a useful mechanism to set aside work you’re not ready to commit yet.

To stash staged changes simply run

git stash

Files in working directory not added to index are not affected, unless you add the -u option to stash those as well.

To view a list of stashes

git stash list

To inspect details of latest stash

git stash show stash@{0}

0 is the id shown by stash list. Use of stash@{0} is optional for latest stash entry.

To apply changes in latest stash to working directory

git stash apply

To eliminate the latest stash (use pop to apply and drop)

git stash drop

If stash apply or pop fails due to conflicts, but you still want to stage the changes, try

git checkout stash -- .

-- indicates current branch. The single dot indicates path beginning at current directory, but may be several different path specs. stash may be replaced with stash@{0}, use a different id to work with older stashes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s