4

I want to save the state of my working area but not as a commit. Should I create a new branch, or is there a way to make a stash without cleaning the working area?

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Slart42
  • 101
  • 9
  • 1
    Why do you want to do this? – Tim Biegeleisen Nov 01 '18 at 23:26
  • 1
    `git stash` makes commits, so in a sense, you're asking how to commit without committing. The only (or at least main) thing special about stash commits is that they're not on any branch. – torek Nov 01 '18 at 23:59
  • @TimBiegeleisen because my program was doing unexpected things, i fix it by doing some change but i wasn't completely sure why that change fixed the problem, and a wanted to analyze it later on and continue working without the issue. – Slart42 Nov 02 '18 at 02:55
  • 2
    `git stash store "$(git stash create)"` should do it. Checkout https://stackoverflow.com/a/53329520/658497 – Noam Manos Jun 28 '19 at 13:39

5 Answers5

8

There's some way to ask stash to save and not remove changes from working tree... but this would work

git stash save "I'm saving"
git stash apply # apply stash, but don't remove it from list of stashes
eftshift0
  • 26,375
  • 3
  • 36
  • 60
1

You could make a commit, and then do a soft reset to back out the state of that commit into the stage and working directory:

git commit -m 'commit for saving'
git reset --soft HEAD~1

The commit you made first would still be available in the reflog, if you wanted to apply it. I actually prefer the answer given by @eftshift0, but this is an option if you wanted an actual commit outside of the stash stack.

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

From @Noam Manos' comment, use git stash store "$(git stash create)". The advantage of this command is that the worktree is not touched (which could affect certain text editors/IDE's).

Check out https://stackoverflow.com/a/53329520/10462623

abrac
  • 521
  • 5
  • 12
0

You can try below

$ git stash
$ git pull - if you want to pull from the master/develop branch
$ git stash pop - To bring your changes back. You might need to resolve conflicts if there are any.
Rmahajan
  • 1,311
  • 1
  • 14
  • 23
0

You can make a branch and save your changes there, But as a commit

I assume you are in masterbranch.

First make a commit.

git commit -m "your commit message"

git checkout -b NEWBRANCH

Now you neet to come back to the master branch

git checkout master

convert your commit again to changes (unstage)

git reset --soft HEAD^

isuruAb
  • 2,202
  • 5
  • 26
  • 39