Run git stash show to Inspect
In this step, we will learn how to inspect the changes stored in a Git stash using the git stash show
command.
Before we can inspect a stash, we need to have one. Let's create a simple file and stash the changes.
First, make sure you are in your project directory:
cd ~/project/my-time-machine
Now, create a new file called notes.txt
and add some content:
echo "Important notes for the future." > notes.txt
Check the status to see the new file:
git status
You should see notes.txt
listed as an untracked file.
Now, let's stash these changes. This will save the changes without committing them and clean your working directory:
git stash save "Add important notes"
You should see output indicating that the changes have been saved and the working directory is clean.
Now that we have a stash, we can inspect its contents using git stash show
. By default, git stash show
shows a summary of the changes in the most recent stash.
Run the command:
git stash show
You should see output similar to this:
notes.txt | 1 +
1 file changed, 1 insertion(+)
This output tells us that one file (notes.txt
) was changed, and it had one line added.
To see the actual content changes (a diff), you can add the -p
or --patch
option:
git stash show -p
This will show you the diff of the changes in the stash, similar to how git diff
works. You should see something like this:
diff --git a/notes.txt b/notes.txt
new file mode 100644
index 0000000..a1b2c3d
--- /dev/null
+++ b/notes.txt
@@ -0,0 +1 @@
+Important notes for the future.
This output shows that a new file notes.txt
was created and the line "Important notes for the future." was added.
The git stash show
command is very useful for quickly checking what changes are contained within a stash without having to apply it. This helps you decide which stash you might want to apply or drop later.