Darren Findlay
Darren Findlay

Reputation: 2563

"Git stash apply" all files, except one

I made a stash of multiple files (30 +) using git stash. I now want to apply the stash to all files except one. What is the best way to achieve this?

Upvotes: 7

Views: 8090

Answers (3)

Orlando
Orlando

Reputation: 9692

You can stage the file you want to preserve by doing

git add <file>

and then use

git stash push --keep-index

This will stash everything but staged files.

Upvotes: 8

Daniel Squires
Daniel Squires

Reputation: 338

Your best bet is to probably to git stash apply then git checkout -- [file] to remove the changes applied when applying the stash.

If you have changes in the file already, your best bet is to commit them before applying the stash, you could then rebase the commit and the stash into a single commit later if you wished.

Upvotes: 10

J j johnson
J j johnson

Reputation: 29

I have a workaround answer. Commit the file. Git stash. Revert the commit.

Upvotes: 2

Related Questions