git cherry-pick 多次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13422280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git cherry-pick multiple commits
提问by BJ Peter DeLaCruz
Possible Duplicate:
How to cherry pick a range of commits and merge into another branch
可能的重复:
如何挑选一系列提交并合并到另一个分支
I want to cherry-pick 19 commits from one branch and apply them to another branch. All of the commits are sequential (commit 1, commit 2 ... commit 19), and the last commit is not the most recent commit (i.e. there are other commits that come after it whose changes I don't want to apply). How can I apply my changes to a branch without typing git cherry-pick
for each commit?
我想从一个分支中挑选 19 个提交并将它们应用到另一个分支。所有提交都是连续的(提交 1,提交 2 ... 提交 19),最后一次提交不是最近的提交(即,在它之后还有其他提交,我不想应用其更改)。如何在不git cherry-pick
为每次提交输入的情况下将我的更改应用到分支?
回答by Oleksandr Kravchuk
git cherry-pick $from_sha..$to_sha
git 樱桃挑选 $from_sha..$to_sha
回答by g19fanatic
A way to do it manually (without cherry picking)
一种手动完成的方法(不采摘樱桃)
make a new branch from the head of your branch where the commits are located git branch newB
从提交所在的分支的头部创建一个新分支 git branch newB
hard reset this new branch to the last commit git reset --hard <shaID of Commit19>
硬重置这个新分支到最后一次提交 git reset --hard <shaID of Commit19>
method 1
方法一
do a mixed reset to the commit directly before the first commit git reset --mixed <shaId of the mentioned commit>
在第一次提交之前直接对提交进行混合重置 git reset --mixed <shaId of the mentioned commit>
do a stash on this 'modified' code to just have the commits 1 to 19 git stash
在这个“修改过的”代码上做一个 stash,只需要提交 1 到 19 git stash
goto where you want to apply this manual cherry pick and do a pop git checkout <dstBranch>
&& git stash pop
转到您想要应用此手动樱桃选择的位置并执行弹出git checkout <dstBranch>
&&git stash pop
method 2(this method will keep the commit msgs)
方法 2(此方法将保留提交消息)
do a hard reset to the commit right before the first commit git reset --hard <shaId of the mentioned commit>
在第一次提交之前对提交进行硬重置 git reset --hard <shaId of the mentioned commit>
do a squashed merge with the reflogs previous state git merge --squash HEAD@{1}
与 reflogs 之前的状态进行压扁合并 git merge --squash HEAD@{1}
now you will see that commits 1 - 19 will be indexed and if you do a commit, the commit msg will be prepopulated with all of the individual commits msgs... allowing you to modify the msg as wanted
现在您将看到提交 1 - 19 将被编入索引,如果您进行提交,则提交信息将预先填充所有单独的提交信息...允许您根据需要修改信息
Now that you have your commit, cherry pick this one commit to where you want it. It has the benefit of having all of the wanted commit msgs.
既然您已经提交了,请在您想要的地方选择这个提交。它的好处是拥有所有想要的提交消息。
when donedelete the temp branch to get rid of all of the junk that you've done to do your internal pick git branch -D newB
完成后删除临时分支以摆脱您为进行内部选择所做的所有垃圾git branch -D newB