Skip to content

Commit 98c09b6

Browse files
committed
Better stash documentation
1 parent ea03371 commit 98c09b6

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

docs/advanced.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: 4 - Advanced Git
44
nav_order: 6
5-
last_modified_date: "2025-05-06 10:46AM"
5+
last_modified_date: "2025-09-16 10:46AM"
66
---
77

88
# Advanced `git`
@@ -75,17 +75,38 @@ $ git stash list
7575
stash@{0}: WIP on main: 26393a3 Another commit
7676
stash@{1}: WIP on main: 4d931c4 Testing rebase
7777
```
78-
If you have only one stash listed, or you want to use the most recent stash (with index `0`), you can pull those files/changes back into your branch with
78+
If you have one or more stashes listed, you have a choice to either `apply` or `pop`
79+
the stash, which are two forms of pulling the changed file(s) back into your working
80+
directory.
81+
82+
**`git stash apply 0`** - applies the changed file(s) of the stash into your project but
83+
leaves the stash. The `0` in this command indicates the index number of the stash.
84+
85+
**`git stash pop 2``** - applies the changed file(s) of the stash into your project but
86+
deletes the stash. The `2` in this command indicates the index number of your stash.
87+
88+
```
89+
$ git stash apply <INDEX>
90+
$ git stash pop <INDEX>
91+
```
92+
93+
However, it is not always obvious what a stash contains, or what changes were incorporated
94+
into it. You can find out more about stashes with these commands:
95+
96+
To show a summary of changes in a stash:
97+
7998
```
80-
$ git stash pop
99+
$ git stash show stash@{<index>}
81100
```
82101

83-
If you have more than one stash listed and want to specify which you want to re-incorporate, you need to `apply` the stash by index (`0`, `1`, `2`, ...)
102+
To show a detailed patch view within a stash:
103+
84104
```
85-
$ git stash pop <INDEX>
105+
$ git stash show -p stash@{<index>}
86106
```
87107

88108
### Create a Branch from a Stash
109+
89110
There are other powerful stash options, such as creating a new branch based on the stash. To do this, list your stashes first to identify the index of the stash you want to work with:
90111

91112
```
@@ -333,4 +354,4 @@ Practice the above skills by doing the following:
333354
8. In a repository with multiple commits, reset your commit history back 3 commits.
334355
9. In a repository with multiple commits, revert your commit history back 2 commits.
335356
10. Create a useful `git alias`.
336-
11. Install the GitHub CLI and use it to list your repositories.
357+
11. Install the GitHub CLI and use it to list your repositories.

0 commit comments

Comments
 (0)