Last Updated: November 19, 2020
·
55.88K
· netbe

Stash only certain files

If you want to stash only specific files, do the following:

  1. Stage the files you don't want to stash
  2. And the following command:

    git stash save --keep-index

For example

# On branch develop
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   fileA
#   modified:   fileB
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   fileC
#   modified:   fileD

git stash save --keep-index 

This will result on fileA and fileB stashed and fileC and fileD not touched

Related protips:

Force a "git stash pop"

1 Response
Add your response

I think what happens is the exact opposite of what you've described above. Files that are staged remain untouched and the modified (but unstaged) files go into the stash with stash save --keep-index

over 1 year ago ·