Skip to content

Commit 1122184

Browse files
authored
Merge pull request #898 from rpjday/stashing_cleaning
Basic cleanup of stash part of "Stashing and Cleaning" section
2 parents 32d73a5 + 6f513b5 commit 1122184

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

book/07-git-tools/sections/stashing-cleaning.asc

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ Often, when you’ve been working on part of your project, things are in a messy
55
The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later.
66
The answer to this issue is the `git stash` command.
77

8-
Stashing takes the dirty state of your working directory – that is, your modified tracked files and staged changes – and saves it on a stack of unfinished changes that you can reapply at any time.
8+
Stashing takes the dirty state of your working directory -- that is, your modified tracked files and staged changes -- and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).
9+
10+
[NOTE]
11+
.Migrating to `git stash push`
12+
====
13+
As of late October 2017, there has been extensive discussion on the Git mailing list, wherein the command `git stash save` is being deprecated in favour of the existing alternative `git stash push`.
14+
The main reason for this is that `git stash push` introduces the option of stashing selected _pathspecs_, something `git stash save` does not support.
15+
16+
`git stash save` is not going away any time soon, so don't worry about it suddenly disappearing.
17+
But you might want to start migrating over to the `push` alternative for the new functionality.
18+
====
919

1020
==== Stashing Your Work
1121

12-
To demonstrate, you’ll go into your project and start working on a couple of files and possibly stage one of the changes.
22+
To demonstrate stashing, you’ll go into your project and start working on a couple of files and possibly stage one of the changes.
1323
If you run `git status`, you can see your dirty state:
1424

1525
[source,console]
@@ -39,7 +49,7 @@ HEAD is now at 049d078 added the index file
3949
(To restore them type "git stash apply")
4050
----
4151

42-
Your working directory is clean:
52+
You can now see that your working directory is clean:
4353

4454
[source,console]
4555
----
@@ -48,7 +58,7 @@ $ git status
4858
nothing to commit, working directory clean
4959
----
5060

51-
At this point, you can easily switch branches and do work elsewhere; your changes are stored on your stack.
61+
At this point, you can switch branches and do work elsewhere; your changes are stored on your stack.
5262
To see which stashes you’ve stored, you can use `git stash list`:
5363

5464
[source,console]
@@ -82,7 +92,7 @@ You can see that Git re-modifies the files you reverted when you saved the stash
8292
In this case, you had a clean working directory when you tried to apply the stash, and you tried to apply it on the same branch you saved it from.
8393
Having a clean working directory and applying it on the same branch aren’t necessary to successfully apply a stash.
8494
You can save a stash on one branch, switch to another branch later, and try to reapply the changes.
85-
You can also have modified and uncommitted files in your working directory when you apply a stash Git gives you merge conflicts if anything no longer applies cleanly.
95+
You can also have modified and uncommitted files in your working directory when you apply a stash -- Git gives you merge conflicts if anything no longer applies cleanly.
8696

8797
The changes to your files were reapplied, but the file you staged before wasn’t restaged.
8898
To do that, you must run the `git stash apply` command with a `--index` option to tell the command to try to reapply the staged changes.
@@ -104,7 +114,7 @@ Changes not staged for commit:
104114
modified: lib/simplegit.rb
105115
----
106116

107-
The apply option only tries to apply the stashed work you continue to have it on your stack.
117+
The apply option only tries to apply the stashed work -- you continue to have it on your stack.
108118
To remove it, you can run `git stash drop` with the name of the stash to remove:
109119

110120
[source,console]
@@ -123,9 +133,7 @@ You can also run `git stash pop` to apply the stash and then immediately drop it
123133

124134
There are a few stash variants that may also be helpful.
125135
The first option that is quite popular is the `--keep-index` option to the `stash save` command.
126-
This tells Git to not stash anything that you've already staged with the `git add` command.
127-
128-
This can be really helpful if you've made a number of changes but want to only commit some of them and then come back to the rest of the changes at a later time.
136+
This tells Git to not only include all staged content in the stash being created, but simultaneously leave it in the index.
129137

130138
[source,console]
131139
----
@@ -142,8 +150,8 @@ M index.html
142150
----
143151

144152
Another common thing you may want to do with stash is to stash the untracked files as well as the tracked ones.
145-
By default, `git stash` will only store files that are already in the index.
146-
If you specify `--include-untracked` or `-u`, Git will also stash any untracked files you have created.
153+
By default, `git stash` will stash only modified and staged _tracked_ files.
154+
If you specify `--include-untracked` or `-u`, Git will include untracked files in the stash being created.
147155

148156
[source,console]
149157
----

0 commit comments

Comments
 (0)