0

Git stash is a very helpful family of commands but it does not add anything to the commands (i.e. you can't commit without the commit command, while you can have workarounds to stash with no stash command).

How would you do it if you had to stash your work but did not have the stash command?

gioaudino
  • 573
  • 8
  • 23
  • I doubt the premise, that you can't commit without the `commit` sub-command. See, for example, the `commit-tree` command for a low-level interface, https://git-scm.com/docs/git-commit-tree. – Boldewyn Jan 16 '17 at 10:09
  • The way I did this with other version control systems was to essentially do `git diff > changes.patch`. And then re-apply them later (with git you can do this via `git apply` or you can use the `patch` command to re-apply it). It's a bear to manage, but possible to do. `git stash` is more friendly though. – John Szakmeister Jan 16 '17 at 10:13
  • Also, you may want to take a look at [Gitless](http://gitless.com/). They've attempted to resolve what they believe are more fundamental issues with Git. In Gitless, when you change branches, it will save your changes with the branch, supposedly removing the need for stash. I disagree with that assertion, but it is an interesting project nonetheless. – John Szakmeister Jan 16 '17 at 10:16
  • Why would you not have the `stash` command? It is part of Git as long as I remember back. What is your exact use-case? – Vampire Jan 16 '17 at 11:05
  • @Boldewyn didn't know that. What I meant is that stash can easily "faked" with a workaround. Commit is less handy. – gioaudino Jan 16 '17 at 13:01
  • @Vampire purely git understanding and deep studies, not a practical use case – gioaudino Jan 16 '17 at 13:01
  • So what exactly was your question then? – Vampire Jan 16 '17 at 13:04
  • Pretend you don't have git-stash for any reason, what command or series of commands would you use to have that behavior? – gioaudino Jan 16 '17 at 13:07

1 Answers1

1

One option which I like is to just make a formal temporary commit on the branch in question, e.g.

# work work work
git commit -m 'Completed the feature'

Now you can switch to another branch and continue from there. When it comes time to return to the original branch, you can finish the feature and amend the temporary commit:

git checkout original_branch
# finish the work
git commit --amend

Now you are left with just a single commit, and you were able to do a hotfix somewhere else.

Note that git stash internally actually makes a commit (2 or 3 of them, actually) to save the state of your working directory and index.

Read the lengthy answer about git stash by @torek by following the link.

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360