我希望能够做到这一点:
git cherry-pick --interactive hash-0..hash-n-1 # fantasy command并获得与交互式rebase相同的工作流程:出现一个编辑器缓冲区,其中包含:
pick hash-0
pick hash-1
pick hash-2
...
pick hash-n-1在那里我可以删除任何不需要的提交,将它们squash在一起,或者使用edit在选择之间暂停,以执行一些手动修复(如commit --amend)等等。
请注意交互式rebase的pick是如何与cherry-pick相似的。
现在可以先执行cherry-pick,然后执行交互式rebase,这是不方便的。这就是:
$ git tag old-head # mark starting point for later rebase
$ git cherry-pick hash-0..hash-n-1 # get everything first
$ git rebase --interactive old-head # okay now rebase "in-branch" to fix it up这不仅因为这两个步骤而不方便,而且因为它可能需要解决提交中的冲突,您甚至不希望这些冲突在rebase阶段被丢弃。
发布于 2014-06-06 13:17:00
好的,想出了一个好办法。
在当前分支中的一次提交上启动一个简单的rebase --interactive HEAD^。你会得到类似这样的结果:
pick 1efd396b * Fixed a bug in frob function现在,只需粘贴您想要挑选的其他散列:
pick 1efd396b * Fixed a bug in frob function
pick f01934db * Awesome feature added
pick 6fd109c1 * Refactored the widgets layer
squash 3900fd77 * Refactored the widgets layer s'more保存并退出,然后wee:rebase mule很乐意接受您加载到它背上的额外cruft,并根据命令将其合并到当前分支中。
实际上,您可以使用以下命令执行一个空的rebase:
git rebase --interactive HEAD你会得到一个缓冲区,其中包含
noop你不必删除它;只需在它之后添加你的选择即可。
附录:要生成此方法的选择列表,请使用git log --oneline --reverse from..to,然后修剪所需的输出,并将rebase命令预先添加到每一行:pick、squash、...
发布于 2014-06-06 13:00:52
好的,根据卡尔·诺鲁姆的建议,我研究了git rebase的--onto争论。
用例可以像这样得到满足,这是一个改进,尽管仍然涉及到一些过多的步骤。
主要的问题是rebase需要一个当前的分支来挑选,所以我们必须将我们的坐标转移到一个临时分支,然后在之后操作我们的原始分支头部并删除临时分支。
流程如下所示:
# We are originally on "mybranch"
# We create a temp-branch pointing to the last commit to be picked: hash-n-1
$ git checkout -b temp-branch hash-n-1 # create branch at last hash
# Then we rebase from the point before the first hash, onto our original branch
$ git rebase --interactive hash-0^ --onto mybranch
# The above rebase should make "temp-branch" into the very object that
# we want "mybranch" to be. If it looks that way, then all that is left is
# make it so:
$ git checkout mybranch
$ git reset --hard temp-branch
$ git branch -D temp-branchgit rebase --interactive hash-0^ --onto mybranch使用hash-0之前的提交作为rebase的“上游”,从当前分支(基于hash-n-1)获取不在上游的所有提交。当然,这些提交是通过hash-n-1的hash-0。它们被重新定位到mybranch头上,但跟踪结果的是当前的temp-branch,它是reset --hard。所以我们只需要将指针赋值给mybranch并删除temp-branch。
它相当笨拙,但消除了重复的挑剔,并且只需使用git reset --hard mybranch就可以随时恢复。
(这还能改进吗?)
发布于 2014-06-06 12:07:01
也许有一个更好的答案,但这可能对你有效。
git cherry | awk '$0=$2' > cherry.txt
"$EDITOR" cherry.txt
git cherry-pick --stdin < cherry.txtExample
https://stackoverflow.com/questions/24073883
复制相似问题