简体   繁体   English

Git:将特定提交移动到另一个分支

[英]Git: move specific commits to another branch

A have repository with two branches. 拥有两个分支的存储库。

Master branch commits: 主分支提交:

c1, c2, c3, c4, c5, c6, c7, ..., c15, ... c1,c2,c3,c4,c5,c6,c7,...,c15,...

Staging Branch commits: 暂存分支提交:

c1, c2, c3, c4, c5, c6, c7 c1,c2,c3,c4,c5,c6,c7

I want to move all commits from Master branch after c7 to staging branch 我想在c7之后将所有提交从Master分支转移到分段分支

and then revert Master branch 然后还原Master分支

with

git reset --hard c7-hash

How to move/copy specific commits from one branch to another ? 如何将特定提交从一个分支移动/复制到另一个分支?

In the case you've described, where all commits on the staging branch are also on the master branch, it's very easy: 在您描述的情况下,登台分支上的所有提交也在主分支上,这很容易:

git checkout staging
git merge master
git checkout master
git reset --hard c7-hash

The merge will be a fast-forward. 合并将是一个快进。

In the general case, you can use git cherry-pick c8 c9 c10 c11 c12 c13 c14 c15 to cherry pick individual commits to the current branch. 在一般情况下,您可以使用git cherry-pick c8 c9 c10 c11 c12 c13 c14 c15来挑选当前分支的单个提交。 A shorter way to cherry pick all commits that are on master but not the current branch is git cherry-pick ..master , and there are other examples shown by git help cherry-pick 一个较短的方法来挑选所有在master上但不是当前分支的提交是git cherry-pick ..master ,还有其他的例子由git help cherry-pick

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

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