File: stash.md

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (109 lines) | stat: -rw-r--r-- 2,125 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
stage: Create
group: Source Code
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://handbook.gitlab.com/handbook/product/ux/technical-writing/#assignments"
---

# Stash changes for later

Use `git stash` when you want to change to a different branch, and you want to store changes that are not ready to be
committed.

- To stash uncommitted changes without a message:

  ```shell
  git stash
  ```

- To stash uncommitted changes with a message:

  ```shell
  git stash save "this is a message to display on the list"
  ```

- To retrieve changes from the stash and apply them to your branch:

  ```shell
  git stash apply
  ```

- To apply a specific change from the stash to your branch:

  ```shell
  git stash apply stash@{3}
  ```

- To see all of the changes in the stash:

  ```shell
  git stash list
  ```

- To see a list of changes in that stash with more information:

  ```shell
  git stash list --stat
  ```

- To delete the most recently stashed change from the stash:

  ```shell
  git stash drop
  ```

- To delete a specific change from the stash:

  ```shell
  git stash drop <name>
  ```

- To delete all changes from the stash:

  ```shell
  git stash clear
  ```

- To apply the most recently stashed change and delete it from the stash:

  ```shell
  git stash pop
  ```

If you make a lot of changes after stashing your changes, conflicts might occur when you apply
these previous changes back to your branch. You must resolve these conflicts before the changes can be applied
from the stash.

## Git stash sample workflow

To try using Git stashing yourself:

1. Modify a file in a Git repository.
1. Stash the modification:

   ```shell
   git stash save "Saving changes from edit this file"
   ```

1. View the stash list:

   ```shell
   git stash list
   ```

1. Confirm there are no pending changes:

   ```shell
   git status
   ```

1. Apply the stashed changes and drop the change from the stash:

   ```shell
   git stash pop
   ```

1. View stash list to confirm that the change was removed:

   ```shell
   git stash list
   ```