Chat Zalo Chat Messenger Phone Number Đăng nhập
How to List Git Stash Entries - phoenixNAP

How to List Git Stash Entries – phoenixNAP

Introduction

A Git stash allows you to hide unfinished work from the current working directory and return to it later. There is no limit to the number of Git caches you can create, which means that the stash reference can contain multiple entries.

In this tutorial, you will learn how to view Git stash entries.

How to view Git Stash entries

Prerequisites

Git

  • installed (follow our tutorials to install Git on Ubuntu, macOS, Windows, CentOS 7, or CentOS 8). A
  • Git

  • repository.

What is Git Stash List?

Creating a stash using the git stash command sets aside uncommitted changes and rolls back the working directory to match the HEAD commit. Git allows users to create as many stash as needed.

When you create a stash using the git stash command, the changes are saved in the refs/stash reference. Each stash entry is assigned an index number, where the last entry is stash@{0}, then comes stash@{1}, and so on.

A Git cache list displays existing hidden entries, the name of the branch on which the entry was created, and a description of the commit on which the entry is based.

How to use Git Stash List?

When you run the git stash list command, a list of all the stash you have created is generated. Customize the output by specifying options that apply to the git log command. The options provide many enhancements and formatting options.

The following sections show different examples of using the git stash list command and the available options.

View

Git stash history View Git stash history by

running the default list command with no options. The command generates the entire booking history.

Run the following command:

git stash list

The most recent stash has the index {0}. Additionally, if specified during creation, the output contains a message for each stash. If there is no hidden message, the output displays the message related to the confirmation on which the stash is based.

See Hyphens

attached to all branches

Use the -all option to display caches attached to all branches instead of showing only the currently active one. Run the following command

: git stash list -all The previous partial output shows the caches of

all Git branches in the repository

. Show limited number of caches If you have a long history of git caches

with many stash entries, specify a limited number of the most recent stash

to display in the output.

The syntax is:

list of git caches -[n

  • ] For [n], Specify the number of caches that you want to display in the output.

For example, to display the two most recent stash

entries, run:

git stash list -2 View stash by date Use the -after option

followed by date to display only the stash more recent than the specified date. Alternatively, use the -before option to display only caches older than the specified date.

Accepted date formats are

: Mon, 5 Jul 2022 17:18:43 +0200 2022-07-05 17:18:43 +0200 Mon Jul 5 15:

    18:43 2022

  • 2022-07-05
  • 5.hours.ago

  • 3.years.2.months.ago
  • 6am yesterday
  • For example, to show only caches older than five days, type: git stash list -before

  • 5.days.ago The result contains only one stash, which was created more than five

  • days ago
  • .

View hidden content

After listing the booking history, view the contents of a specific stash by using the show command. The syntax is:

git stash show stash@{n}

  • For {n}, specify the hiding index whose contents you want to view.

For example, to view the

contents of stash{0}, run:

git stash show stash@{0}

The output shows the hidden files, along with the number of file insertions and deletions

. View changes to

Git stash entries

Specify the -p option to see the difference in changes for each stash. Run the following command:

git stash list -p

The above partial output shows the differences for stash{0}. To see other stash differences, scroll through the terminal window.

Alternatively, to

see the difference between a stash and the local Git worktree, specify the stash you want to compare.

The syntax is:

git stash show -p stash@{n}

View statistics for hidden files

Specify the -stat option to generate a summary of changes for each file in the Git cache history. Run the following command:

git stash list -stat

The command displays the number and summary of changes for the files in

each stash. Show detailed list of caches For a concise list of Git

caches

with

more details about each cache, specify the -oneline option with the list command. Enter the following:

list of git caches -oneline

The command generates a list of caches

, the cache confirmation STASH, the storage paths, and a message created for the stash, or the confirmation message on which the stash is based.

Conclusion

This tutorial showed how to enumerate Git stash entries in a repository and use different command options to format and customize the output

.

Learn more about Git in our tutorials for restoring a Git stash, dropping a Git stash, or saving specific files.

Contact US