How do I stash just some of my uncommitted changes?

喜夏-厌秋 提交于 2019-12-11 01:46:36

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/49886083/how-do-i-stash-just-some-of-my-uncommitted-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!