Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stashing only un-staged changes in Git

Tags:

git

git-stash

I would like to use this workflow:

  1. Stage some changes.
  2. Save the unstaged changes to the stash.
  3. Do some stuff with the things in stage (build, test, etc.).
  4. Commit.
  5. Restore the unstaged changes.

Is there a way to do step 2?

Example:

git init echo one >file git add file git commit echo two >>file git add file echo three >>file git stash push test git commit git stash pop 
like image 926
Unapiedra Avatar asked Oct 04 '11 16:10

Unapiedra


People also ask

How do you stash unstaged changes only?

Stage all your files that you need to stash. Run git stash --keep-index . This command will create a stash with ALL of your changes (staged and unstaged), but will leave the staged changes in your working directory (still in state staged). Now your "good stash" has ONLY staged files.

What does stashing changes mean in git?

Stashing your work The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.

How do I stash changes not staged for commit?

Git doesn't have a command that stashes only your unstaged changes. Git does, however, let you specify which files you want to stash. If you only want to stash specific changes in those files, add the --patch option. The --include-untracked option lets you stash untracked files.


1 Answers

git stash push has an option --keep-index that does exactly what you need.

So, run git stash push --keep-index.

like image 177
vhallac Avatar answered Sep 29 '22 13:09

vhallac