View a list of cache entries in Git
We often need to pause our work and focus on something else in our development environment. Therefore, we may need to temporarily save our current work and focus on a different one. We may want to resume our original work later.
git stash
The command provides the stash functionality of Git, which allows us to temporarily save the changes we have made to the work at hand. It will enable us to restore our work later by retrieving it from the temporary cache.
We can do this temporary work saving operation multiple times. Therefore, we want to see the list of such cache entries and their contents. git stash
The command provides us with the option to browse the list of cache entries.
In this article, you will learn how to view the list of cache entries in Git. We will now illustrate this with an example.
View the list of Stash items in Git
git stash
The command allows us to record the current state of the project repository's working directory. It also allows us to save the current state of the index.
git stash
The command saves the local changes and restores the working directory to match HEAD
the commit. We can perform the operation of shelving the changes on the working copy multiple times.
So, after executing caching multiple times, we now have a list of cache entries in our project's Git repository. We can git stash list
view the list of cache entries using the command.
The most recent cache entry we created is cached in refs/stash
. Older caches can reflog
be found in this reference. The most recently created cache entry is named stash@{0}
. Its predecessor was named stash@{1}
, and so on.
A cache can be referenced by specifying its index. For example, the integer n
is equivalent to stash@{n}
.
After creating some cache entries we can view them like this.
$ git stash list
stash@{0}: WIP on main: b14f387 some work
stash@{1}: WIP on main: b14f387 some other work
stash@{2}: WIP on main: b14f387 some older work
As shown above, we can main
see a list of three stash entries in the Git repository's branch. We can also view the contents of each stash entry.
To see the files in the latest cache entry, we need to follow.
$ git stash show
test.txt | 4 ++++
1 file changed, 4 insertions(+)
We can see that test.txt
Recently has been hidden.
To see the changes to the files in the most recent stash entry, we need to do the following.
$ git stash show -p
diff --git a/test.txt b/test.txt
index fae50f7..f60e878 100644
--- a/test.txt
+++ b/test.txt
@@ -73,4 +73,16 This test
some old text
+ some new text
+1. Add this
+2. Add that
+
git stash show
The command displays the changes recorded in a cache entry as the difference between the cache contents and the commit that was returned when the cache entry was first created.
We can also view a specific cache using its name. We need to git stash show -p <named-stash>
provide the name in .
So, to view stash@{1}
the cache entry named , we would execute the following command.
$ git stash show -p stash@{1}
We can also see cache entries across branches, not just the current one. To do this, we need to execute the following command.
$ git stash list --all
We can also view the cache history in Git by date range. We need to use the command with option -r --before
or --after
-r git stash list
.
We can execute the command with date range as follows.
$ git stash list --before 3.days.ago
$ git stash list --after 2.days.ago
We can -stat
summarize the changes in each element of git stash history using -r option. As shown below, we can -stat
execute the command using -r option.
$ git stash list --stat
So, we showed how to view a list of cache entries in Git.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Git installation and establishment of local warehouse service
Publish Date:2025/04/05 Views:89 Category:Git
-
Git is a distributed version control system: the client does not only extract the latest version of the file snapshot, but also completely mirrors the original code repository. It has the following advantages: a. Since every extraction oper
git remote operation——multiple remote repositories for one project
Publish Date:2025/04/05 Views:131 Category:Git
-
Multiple remote repositories for a git project In our git project, the command to operate the remote repository information is $ git remote # 查看当前所有的远程仓库的名称 $ git remote -v # 查看远程仓库的名称和远程仓
Git cherry pick command usage
Publish Date:2025/04/05 Views:190 Category:Git
-
git cherry-pick is a powerful command that allows us to select an arbitrary Git commit by reference and attach it to the HEAD of the current working branch. Cherry picking is the act of picking a commit from one branch and applying it to an
Comparison between Git merge and Git rebase
Publish Date:2025/04/05 Views:171 Category:Git
-
The git rebase command may seem like Git wizardry to beginners, but if used carefully, it can actually make life easier for your development team. In this article, we compare git rebase with the related git merge command and identify all th
How to fix Git error Error: src refspec master does not match any
Publish Date:2025/04/05 Views:124 Category:Git
-
When using Git, we may encounter the error "src refspace master does not match any". Here's what the error means and how to fix it. What does src refspec master does not match any Mean in Git mean? We may encounter this error when we try to
Rebase local branch when pulling changes from remote repository branch in Git
Publish Date:2025/04/05 Views:144 Category:Git
-
This article will cover the basics of rebasing your local branch when pulling changes from a remote repository branch in Git. We use the version control system Git to track changes made to files. We commit changes in a local branch in our l
Undo Git Stash
Publish Date:2025/04/04 Views:187 Category:Git
-
This article explains how to make and save changes to a repository. Git allows you to save changes locally and push them to a server when needed. In Git, we don't use the term save , but commit . We use git add , git commit , and git stash
Git stores specific files
Publish Date:2025/04/04 Views:115 Category:Git
-
This article will cover storing changes to only specific files in Git. In Git, when we make some changes in our working tree, we may have some changes which may or may not be staged in our local repo. We may now wish to save these changes f
Git Stash and Shelve in IntelliJ IDEA
Publish Date:2025/04/04 Views:113 Category:Git
-
git stash This article will distinguish between and when using IntelliJ IDEA git shelve . These two come into play when we want to switch between multiple tasks while working and return to them later. IntelliJ IDEA allows us to work on diff