我已经从GitHub的存储库中分叉了一个分支,并提交了一些具体的东西给我。现在我发现原来的存储库有一个很好的功能,这是在HEAD。

我想合并它只是没有以前的提交。我该怎么办?我知道如何合并所有的提交:

git branch -b a-good-feature
git pull repository master
git checkout master
git merge a-good-feature
git commit -a
git push

当前回答

如果您已将更改提交给主分支。现在您想要将相同的提交移动到release分支。检查提交id(例如:xyzabc123)。

现在试试下面的命令

git checkout release-branch
git cherry-pick xyzabc123
git push origin release-branch

其他回答

您可以使用git自行选择将单个提交应用到当前分支。

例如:git选择d42c389f

我会提出一个答案。这就是通过Export手动更改并提交到目标分支,对于使用像tortoise这样的工具,导出可以真正有效地实现这一点。我知道这在SVN中工作得很好,到目前为止,在git的一些测试中也取得了同样的成功,只要它们是100%相同的,就不应该在未来合并特性分支时解决任何冲突。

Let me show an example: c:/git/MyProject_Master/ModuleA/ c:/git/MyProject_FeatureA/ModuleA/ Let's suppose we wanted all the files from ModuleA's FeatureA branch to be in the master branch. Assume for a moment this is a huge project and there are other modules, and we know from experience that ModuleA has no dependencies that would cause a compiler or functional issue from the new changes of the feature branch. Select the ModuleA folder and choose Export from tortoise. Then pick ModuleA of master to export it into. Finally, do a file difference check on each file to review the changes, using the diff tool, be sure that all calls out are still compatible. Make sure it compiles, thoroughly test. Commit, push. This solution is a time-tested and effective for svn.

我们将不得不使用git cherry-pick <commit-number>

场景:我在一个名为发布的分支上,我只想从主分支添加一些更改到发布分支。

步骤1:签出您想要添加更改的分支

Git签出版本

步骤2:获取你想要添加的变更的提交号

例如

git cherry-pick 634af7b56ec

第三步:git push

注意:每次合并都会创建一个单独的提交号。不要为不能工作的合并取提交号。相反,是你想添加的任何常规提交的提交号。

假设你想合并提交e27af03从分支X到主分支。

git checkout master
git cherry-pick e27af03
git push

如果你是新手,尝试GitHub桌面版本,当你选择选择选项时,GitHub会要求你选择你想要提交的分支。

1)

2)