导出特定的Git作为补丁提交 [英] Export specific Git commits as patches

查看:116
本文介绍了导出特定的Git作为补丁提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将多个提交(包含提交消息中特定票证编号1234的提交)导出到补丁文件。

>工作脚本位于 https://github.com/amenk/SelfScripts / blob / master / git-extract-patches



这就是我的

 #!/ bin / bash -x 
commits =`git log --pretty = oneline | grep#1234| cut -f1 -d`
no = 1;
for $ COMMIT
do
git format-patch -1 $ COMMIT --start-number = $ no
no = $(($ no + 1))
完成

但由于某些原因执行git format-patch失败:

  $ ./getpatches.sh 
++ git log --pretty = oneline
++ grep'#6809'
++ cut -f1'-d'
+ commits ='da591d66f05513488ee06857edc9d24a046c179d
4fd781da9cc503b961f8e4c42bbb136d9e3c1806
3a9311f5507f91f830b44673c57f672e7aabaac0'
+ no = 1
+ for COMMIT in'$提交'
+ git format-patch -1'da591d66f05513488ee06857edc9d24a046c179d'--start-number = 1
致命:不明确的参数'da591d66f05513488ee06857edc9d24a046c179d':未知修订或路径不在工作树中。
使用' - '将路径与修订分开

当我调用 git format-patch -1'da591d66f05513488ee06857edc9d24a046c179d'--start-number = 1 手动,一切正常。



编辑:



我认为这是引用内容。如果我添加一个 git log | grep $ COMMIT 进入循环,我得到以下错误:

  + grep'992ab41d3539539bd609209beed33a9de2f4277a'
grep:不匹配[或[^

另一个影响因素是,如果我硬编码 grep'992ab41d3539539bd609209beed33a9de2f4277a'在for循环中,命令输出(因为 -x 选项用于
$ b

  + grep 992ab41d3539539bd609209beed33a9de2f4277a 
没有引号, code>

这些引用来自哪里,我如何摆脱它们?

解决方案

我的git隐式地使用了 - color 选项,所以 $ COMMIT

但是你没有看到这一点,因为这是一个错误消息。在终端(这只是五颜六色的),也没有后



解决方案是:
$ b $ pre $ b $ commit = git log --no-color --pretty = oneline | grep#1234| cut -f1 -d`


I am trying to export several commits (those that contain a specific ticket number 1234 in the commit message) to patch files.

EDIT The working script is on https://github.com/amenk/SelfScripts/blob/master/git-extract-patches

This is what I have

#!/bin/bash -x
commits=`git log --pretty=oneline | grep "#1234" | cut -f1 -d" "`
no=1;
for COMMIT in $commits
do
    git format-patch -1 $COMMIT --start-number=$no
    no=$(($no+1))
done

But for some reason executing of git format-patch fails:

$ ./getpatches.sh 
++ git log --pretty=oneline
++ grep '#6809'
++ cut -f1 '-d '
+ commits='da591d66f05513488ee06857edc9d24a046c179d
4fd781da9cc503b961f8e4c42bbb136d9e3c1806
3a9311f5507f91f830b44673c57f672e7aabaac0'
+ no=1
+ for COMMIT in '$commits'
+ git format-patch -1 'da591d66f05513488ee06857edc9d24a046c179d' --start-number=1
fatal: ambiguous argument 'da591d66f05513488ee06857edc9d24a046c179d': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

When I call git format-patch -1 'da591d66f05513488ee06857edc9d24a046c179d' --start-number=1 manually, everything is fine.

EDIT:

I think it is something with the quotes. If I add a git log | grep $COMMIT into the loop, I get the following error:

+ grep '992ab41d3539539bd609209beed33a9de2f4277a'
grep: Unmatched [ or [^

Another interseting effect is, if I hard-code grep '992ab41d3539539bd609209beed33a9de2f4277a' in the for loop, the command output (because of the -x option for bash is without the quotes and it works.

 + grep 992ab41d3539539bd609209beed33a9de2f4277a

Where are these quotes coming from and how do I get rid of them?

解决方案

My git was implicitly using the --color option so the $COMMIT string contained some color codes. So this messed up the parsing. Interesting, that also the color was contained in my error messages.

But you do not see this in the terminal (it's just colorful), and also not after pasting to stack overflow.

The solution is:

commits=`git log --no-color --pretty=oneline | grep "#1234" | cut -f1 -d" "`

这篇关于导出特定的Git作为补丁提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆