git cherry picking one commit to another branch

天大地大妈咪最大 提交于 2020-01-17 03:14:09

问题


In developing for a work enviornment, we create a branch for each feature or fix we work on, and then merge to QA for testing.

Occasionally I find it's helpful to have a stash which contains console.logs' of debugging steps for a specific process. But I want to only have that be a subset of files in my working copy.

So, I am considering creating another branch for local use with commits which will be used later. Which don't reference a specific ticket necessarily.

So the question is, how can I take a specific commit in this "useful items" branch, and apply it to another branch? I'm sorry if I'm using the term cherry pick incorrectly here. I use sourcetree but am able to use command line for this also.


回答1:


there are several ways to achieve it (you have to be on the branch you want to apply the commit to),

you can create a patch of the commit you want then apply it

git format-patch <commit sha1> 
git apply <patch path>

or you can indeed cherry-pick the commit you want

git cherry-pick <commit sha1>


来源:https://stackoverflow.com/questions/36777547/git-cherry-picking-one-commit-to-another-branch

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