Mastering git, Part 6, git stash

Sometimes you have made some changes into your local copy and you don’t want to make a commit because your code doesn’t compile, but something came up and you should change your branch for instance and you will lose your local changes. In this situation, you can stash your changes and save your changes and change your branch for instance. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

Let’s have a complete example:

now we make some change:

now let’s stash changes:

stash@{0} is the most recently created stash, stash@{1} is the one before it. WIP stands for work iprogress. We can list and drop changes by:

We can use gitk to see the changes and :

Now let’s create a branch and one more stash and apply the previous stash from the master branch there:

To see all stash in gitk

To checkout a specific file from stash:

To view the file in the stash:

stash@{0}^1 means the first parent of the given stash, which as stated in the explanation above is the commit at which changes were stashed away.


0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x