Bill
Bill

Reputation: 45408

How do I stash just some of my uncommitted changes?

I was in the middle of a major change in my Git repo and realized that some of the changes needed to be backported to a bugfix branch. I don't want to check in all of my changes to master because they're not fully tested and ready, but I do want to pull a few of these changes out and commit them to the bugfix branch, then return to master with my index as it was.

How can I avoid committing all my changes to master but still commit some of these changes to my bugfix branch?

Upvotes: 2

Views: 464

Answers (1)

Bill
Bill

Reputation: 45408

It took me a while to figure this out, but:

git stash --patch
# select just the changes that you're not ready to commit

# now you have just the bugfix changes left in your index, so..
git stash

git checkout bugfix-branch
git stash pop
git commit -m "...."

git checkout master
git stash pop

Upvotes: 4

Related Questions