Reputation: 63506
I want to apply some of the changes in a git stash to one commit, and the rest of the changes to another.
Upvotes: 48
Views: 20669
Reputation: 962
git checkout stash@{0} -- <filename>
You can also do this with a list or a glob of filenames.
Upvotes: 67
Reputation: 3549
Apply the patch for only the files you want to change.
git show --first-parent stash@{0} -- <file(s) in question> | git apply
Upvotes: 12
Reputation: 38113
Looks like you can use git checkout -p
with a stash reference, like stash@{0}
. This will let you choose piece by piece what you want to apply to your work tree from the stash.
After you're done using git checkout -p
, the changes you accepted will have been applied to your work tree and added to the cache/index, ready to commit. You can use git checkout -p stash@{0}
multiple times, choosing the patches you want and committing however many times you want along the way.
Upvotes: 30
Reputation: 490143
Unstash the stash...
git stash pop
...use git add
in patch mode...
git add -p
...and then commit that...
git commit -m "Partial stashed commit"
This is what quickly came to my head without reading the docs. Leo's answer has much better way to achieve this.
Upvotes: 6