简体   繁体   English

如何合并以前的提交

[英]How to merge previous commits

I've setup Gitlab and I'm trying to follow the workflow mentioned here: Gitlab Production branch flow. 我已经设置了Gitlab,并尝试遵循此处提到的工作流程: Gitlab Production分支流程。

Now my repository looks like this: 现在我的存储库如下所示:

在此处输入图片说明

And I've been asked to merge only commit A of the master branch with the production branch. 我被要求只将master分支的commit Aproduction分支合并。 What is the best way to do this? 做这个的最好方式是什么?

Should I use the git cherry-pick command? 我应该使用git cherry-pick命令吗? I read I'll loose the version history with the cherry-pick . 我读到我将使用cherry-pick释放版本历史记录。

If I've this situation where I need to keep merging one of the previous commits from master branch to the production branch, how do I handle this? 如果遇到这种情况,我需要继续合并以前从master分支到production分支的提交之一,该如何处理?

I'm stuck at this. 我被困在这里。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Thanks, 谢谢,

Update: From master branch I can push only specific commits: git push <remotename> <commit SHA>:<remotebranchname> 更新:我只能从master分支推送特定的提交: git push <remotename> <commit SHA>:<remotebranchname>

Found answer here: How can I push a specific commit to a remote, and not previous commits? 在这里找到答案: 如何将特定的提交推送到远程而不是以前的提交?

Cherry picking is viable if you specifically want the changes made in select commits. 如果您特别希望在选择提交中进行更改,则选择樱桃是可行的。 It's most beneficial when the commits you need to apply didn't occur in sequential order. 当您需要应用的提交未按顺序进行时,这是最有益的。 Personally, I wouldn't recommend you do this on master/production branches as it's not a good long term release strategy. 就个人而言,我不建议您在主/生产分支上执行此操作,因为这不是一个好的长期发布策略。

My advice is based on git flow, which I know is somewhat different to GitLab's approach. 我的建议基于git flow,我知道它与GitLab的方法有些不同。

If these are actual releases, consider following a release branch workflow, where in this case you create a release branch on commit A , and then merge into production. 如果是实际发行版,请考虑遵循发行版分支工作流程,在这种情况下,您需要在commit A上创建发行版分支,然后合并到生产中。

If these are bugfix/hotfixes needing some commits but not all (requiring cherry-picking), you could create a hotfix branch from your production branch, cherry-pick the commit you need to that branch first, then when testing is finalized merge that back into production. 如果这些是需要一些提交但不是全部提交的错误修正/修补程序(需要挑选樱桃),则可以从生产分支中创建一个修补程序分支,先选择您需要对该分支的提交,然后在测试完成后将其合并投入生产。 If any extra changes or commits are applied in that branch they will need to be merged back into whatever your development branch is as well. 如果在该分支中应用了任何其他更改或提交,则它们将需要重新合并到您的开发分支中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM