Git

How to Show an Individual Stash?

While working on Git, developers make unnecessary changes that are not required to add to their project. In this situation, users store those changes in the stash and use them whenever they need. Sometimes, it is needed to view those changes for different reasons. For this corresponding purpose, different Git commands are available to view stash changes.

This write-up will discuss:

How to Show Stored Changes of Individual Stash?

To display the stored changes of individual stash, first, view the available stashes in the repository:

$ git stash list

It can be seen that there is only one stash in the repository:

Then, run the below-provided command along with the particular stash reference to display its changes:

$ git stash show stash@{0}

The below output shows the list of (tracked) files stored in the stash:

How to Show Stored Changes With the Patch Format of Individual Stash?

Utilize the below-provided command along with the “-p” flag to view stash changes with the patch format:

$ git stash show stash@{0} -p

The changes of files stored in the stash can be seen in the given output:

How to Show All Stash Changes Including Untracked Files of Individual Stash?

The simple “git stash show stash@{0}” command only displays the tracked file’s stash changes. In order to view the untracked files of individual stash, utilize the “-u” option in the same command:

$ git stash show stash@{0} -u

Here, it can be seen that the following output shows the untracked file’s changes also, i.e., “f1.txt”:

Alternatively, users can utilize the “–include-untracked” option to show the untracked file’s changes:

$ git stash show stash@{0} --include-untracked

How to Show Only Untracked Changes of Individual Stash?

Sometimes, users just want to display the untracked file changes of a particular stash. In this situation, the “–only-untracked” option can be utilized with the previous command:

$ git stash show stash@{0} --only-untracked

We have efficiently explained different ways to show individual stash in Git.

Conclusion

There are different ways to show or display the stash in Git, such as if the user only wants to view the stored changes of an individual stash, the “git stash show stash@{<reference-no>}” command can be used. For the patch format, utilize the “-p” option with the same command. Furthermore, “-u” and “–include-untracked” options are used to display all the changes including the untracked file changes of individual stash. Moreover, you can view only the untracked file’s changes of the stash using the “–only-untracked” option. This write-up explained the different methods to display an individual stash.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.