So when I git stash
it will pack my changes since the last commit to a list, however is their any way that I do not have to commit, but still stash and keep the uncommitted changes or of their is any other git command for that ?
Asked
Active
Viewed 620 times
0

Ciasto piekarz
- 7,853
- 18
- 101
- 197
-
It's not clear what you want to do. `stash` [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.](https://git-scm.com/book/en/v1/Git-Tools-Stashing) – U r s u s Aug 26 '15 at 12:43
-
1Dont forget that you can name your stash to retrieve it more easily later with `git stash save "thenameyouwant"` . Then you can list all your stashes with `git stash list` (it will display the name if you've given one).. then you can `git stash apply` the stash you want – arnaudbey Aug 26 '15 at 12:54
2 Answers
3
You with a single command you can't. But you can stash the changes and then apply they back, keeping them into the stash. Check the stash docs for more info.
git stash
git stash apply
If you want, you can create a alias in your .gitconfig file. You can check how to create alias here.
[alias]
stash-save = !git stash && git stash apply

Cristiano Araujo
- 1,632
- 2
- 21
- 32
-
in the alias is it possible to pass optional flag that should do `stash list` too ? – Ciasto piekarz Aug 26 '15 at 16:26
-
just put another command like : stash-save = !git stash && git stash apply && git stash list – Cristiano Araujo Aug 26 '15 at 21:00
-
if you wan't to be a option, the you must create a script, but then create a stash-save.sh script and put it on your path – Cristiano Araujo Aug 26 '15 at 21:01
0
If you have changes that you would like to keep around but not have to keep in your stash stack perhaps you could store them on a separate topic branch.
So, the procedure would be:
# do some work
# realize you want to go in another direction but keep your changes somewhere
git checkout -b topicName
git add .
git commit -m "useful description"
git checkout - # go back to previous branch
Then, whenever you want you can either merge or cherry-pick the "stashed" away changes on that topic branch back on to the branch you are working on.
git merge topicName

Jonathan.Brink
- 23,757
- 20
- 73
- 115
-
Typically the reason to want a diff to hang around as a stash and not as a commit is because it's required to temporarily integrate or exercise a feature while awaiting a team member to finish some concurrent work. You want it as a stash because you might want to switch branches here and there; you don't want it on a branch because you're working on a branch already. And you don't want the changes in the history because they're ephemeral and designed to be thrown away. – Barry Kelly Jan 17 '18 at 10:32