How can i stash without cleaning the working area?

Viewed 928

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?

5 Answers

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

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.

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.

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^

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

Related