我从我主人那里得到了两个分支:

v2.1:(版本2)我已经做了几个月了 wss:我昨天创建了一个特定的功能添加到我的master(在生产中)

有没有办法将昨天的提交从wss复制到v2.1?


当前回答

上面已经提到的答案涵盖了大部分内容,但有一件事似乎被遗漏了,那就是选择的——no-commit特性。

假设,您在特性分支上有多个提交,您希望将它们“合并”为一个提交,并将它们放在您的主分支上。在这种情况下,你需要做的是:

git checkout <branch-on-which-to-add-features>
git cherry-pick --no-commit <commit-hash>
git cherry-pick --no-commit <commit-hash>
.
.
.

最后,一旦你选择了所有需要的特性,你可以做最后的提交:

git commit -m "Some message for the merge commit"

理想情况下,就像@Cascabel提到的,你应该使用merge或rebase。但如果你觉得没有其他选择,你可以使用樱桃选择。

其他回答

您可以从想要复制的提交中创建一个补丁,并将该补丁应用到目标分支。

假设我已经向主分支提交了更改。 现在我将获得提交的提交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

或者如果你不太站在福音派这边你可以用我用的丑陋的方法。在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.

对于从分支wss复制最后一次提交到v2.1的简单情况,你可以简单地获取提交id (git log——oneline | head -n 1),然后执行:

git checkout v2.1
git merge <commit>