我从我主人那里得到了两个分支:
v2.1:(版本2)我已经做了几个月了 wss:我昨天创建了一个特定的功能添加到我的master(在生产中)
有没有办法将昨天的提交从wss复制到v2.1?
我从我主人那里得到了两个分支:
v2.1:(版本2)我已经做了几个月了 wss:我昨天创建了一个特定的功能添加到我的master(在生产中)
有没有办法将昨天的提交从wss复制到v2.1?
当前回答
假设我已经向主分支提交了更改。 现在我将获得提交的提交id (xyz)。 然后我必须去到我需要推送提交的分支。
单次提交id xyz
git checkout branch-name
git cherry-pick xyz
git push origin branch-name
多个提交id xyz abc qwe
git checkout branch-name
git cherry-pick xyz abc qwe
git push origin branch-name
其他回答
cherry-pick命令可以从标准输入读取提交列表。
下面的命令选择用户John在“开发”分支中但不在“发布”分支中的提交,并按时间顺序执行。
git log develop --not release --format=%H --reverse --author John | git cherry-pick --stdin
对于从分支wss复制最后一次提交到v2.1的简单情况,你可以简单地获取提交id (git log——oneline | head -n 1),然后执行:
git checkout v2.1
git merge <commit>
您可以从想要复制的提交中创建一个补丁,并将该补丁应用到目标分支。
或者如果你不太站在福音派这边你可以用我用的丑陋的方法。在deploy_template中,有一些提交需要作为分支部署复制到主节点上
git branch deploy deploy_template
git checkout deploy
git rebase master
这将在deploy_template上创建新的分支deploy(我使用-f来覆盖现有的deploy分支),然后将这个新分支重新基于master,不改变deploy_template。
这是另一种方法。
git checkout {SOURCE_BRANCH} # switch to Source branch.
git checkout {COMMIT_HASH} # go back to the desired commit.
git checkout -b {temp_branch} # create a new temporary branch from {COMMIT_HASH} snapshot.
git checkout {TARGET_BRANCH} # switch to Target branch.
git merge {temp_branch} # merge code to your Target branch.
git branch -d {temp_branch} # delete the temp branch.