git cherry pick - 提交范围并排除介于两者之间的一些
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15687346/
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 - range of commits and exclude some in between
提问by user2125827
I normally use the following git command to cherryppick a range of gerrits..no how do I exclude a couple gerrits in between.. can the below command be modified or is there one where we can pick a range of gerrits and exclude the ones we want..
我通常使用以下 git 命令来挑选一系列的 gerrits.. 不,我如何排除中间的几个 gerrits.. 可以修改下面的命令,或者我们可以选择一系列的 gerrits 并排除那些我们想..
git cherrypick fromgerritSHA1..togerritSHA1
回答by twalberg
You can specify multiple ranges:
您可以指定多个范围:
git cherry-pick A..B C..D E..F
or even specific commits:
甚至特定的提交:
git cherry-pick A B C D E F
If you have lots of commits you want to exclude, it might be easier to do something like this (sort of like a poor man's git rebase -i
for git cherry-pick
):
如果您有很多要排除的提交,那么做这样的事情可能会更容易(有点像穷人的git rebase -i
for git cherry-pick
):
git log --pretty=oneline A..F | tac > tempfile.txt
< edit tempfile.txt to remove the commits you don't want >
git cherry-pick $(awk '{print }' tempfile.txt)
Edit: Added recommendation to tac
the log, since git cherry-pick
wants to see the commits in the opposite order from what git log
produces (could also use git log --reverse ...
).
编辑:向tac
日志添加了建议,因为git cherry-pick
希望以与git log
生成相反的顺序查看提交(也可以使用git log --reverse ...
)。
回答by Rob Bajorek
Not sure if you can pull individual commits out of a range abcdef..123456
. Git range syntax is explained in the docs for gitrevisions, and it doesn't look like it works that way. Still, there's another way to get what you want using only the range hashes and the ones to exclude.
不确定您是否可以将单个提交拉出范围abcdef..123456
。Git 范围语法在gitrevisions的文档中进行了解释,但它看起来不像那样工作。尽管如此,还有另一种方法可以仅使用范围哈希和要排除的哈希来获取您想要的内容。
Assuming the two hashes in range fromgerritSHA1..togerritSHA1
that you don't want are skiphash1
and skiphash2
, try:
假设fromgerritSHA1..togerritSHA1
您不想要的范围内的两个散列是skiphash1
and skiphash2
,请尝试:
$ git rev-list --reverse fromgerritSHA1..togerritSHA1 | grep -vE 'skiphash1|skiphash2' | git cherry-pick --stdin
git rev-list --reverse fromgerritSHA1..togerritSHA1
prints out commit hashes in range fromgerritSHA1..togerritSHA1
, one line at a time. --reverse
is needed to list the hashes in the correct order for the cherry-pick.
git rev-list --reverse fromgerritSHA1..togerritSHA1
打印出 range 中的提交哈希fromgerritSHA1..togerritSHA1
,一次一行。--reverse
需要以正确的顺序列出樱桃挑选的哈希值。
grep -vE 'skiphash1|skiphash2'
removes the two hashes you don't want from the list. You can add more hashes to skip, just separate them with |
.
grep -vE 'skiphash1|skiphash2'
从列表中删除您不想要的两个散列。您可以添加更多要跳过的哈希值,只需将它们用|
.
Finally, the list of only the commit hashes you want is passed to git cherry-pick --stdin
.
最后,仅将您想要的提交哈希列表传递给git cherry-pick --stdin
.
回答by János
If you got problem during cherry-pick like below, try to choose starting hash one beforethan your original attempt was.
如果您在如下所示的挑选过程中遇到问题,请尝试在您最初的尝试之前选择一个开始哈希。
git cherry-pick a005efa..1ece685
[temp_4454kjerer3233 3520dd4] 3. xxx.
1 file changed, 9 insertions(+)
[temp_4454kjerer3233 791cec5] 4. xxx.
3 files changed, 19 insertions(+)
[temp_4454kjerer3233 2e95364] 5. xxx.
2 files changed, 21 insertions(+)
[temp_4454kjerer3233 59e38b9] 6. xxx.
3 files changed, 61 insertions(+)
error: could not apply a3b0c6b... 7. xxx.
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'