git生成patch,应用到rpmbuild 打补丁

来源:互联网 发布:怎样做网络推广话术 编辑:程序博客网 时间:2024/06/10 04:35

git diff > test.patch
git format-patch
不要再用diff命令 对比生成patch了,太土

原来的rpm制作,打patch方法(土):
http://blog.csdn.net/qq_26437925/article/details/73864258

centos下 rpm制作

运行环境

[root@localhost myrpm_build]# uname -aLinux localhost 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

不同的运行环境需要调整自己的spec文件

[root@localhost myrpm_build]# tree helloworld-0.1helloworld-0.1├── configure├── helloworld.c└── readme0 directories, 3 files[root@localhost myrpm_build]# 

configure

#!/bin/shcat >Makefile  << EOFall:helloworldhelloworld.o:helloworld.c        gcc -c helloworld.chelloworld:helloworld.o        gcc helloworld.o -o helloworldfresh:        rm -f Makefileclean:        rm -f helloworld helloworld.oinstall:        cp helloworld /usr/binuninstall:        rm -f /usr/bin/helloworldEOF

helloword.c

#include <stdio.h>int main(){    printf("Hello World!\n");    return 0;}

helloworld.spec

Summary:the first rpmName:helloworldVersion:0.1Release:1%{?dist}Vendor:johnLicense:ShareGroup:Applications/TextSource0:%{name}-%{version}.tar.gz# add patch%descriptionhelloworld.rpm build test%prepexport RPM_SOURCES_DIR=/root/rpmbuild/SOURCESexport RPM_BUILD_DIR=/root/rpmbuild/BUILDtar -xzvf $RPM_SOURCES_DIR/%{name}-%{version}.tar.gz%buildcd $RPM_BUILD_DIR/%{name}-%{version}./configuremake%installcd $RPM_BUILD_DIR/%{name}-%{version}make installmkdir -p /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/cp $RPM_BUILD_DIR/%{name}-%{version}/%{name} /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/%cleanrm -rf $RPM_BUILD_DIR/%{name}-%{version}%files%defattr(-,root,root)/usr/bin/%{name}%doc $RPM_BUILD_DIR/%{name}-%{version}/readme

如下两句是由于rpmbuild -ba helloworld.spec报错,根据报错信息添加的,可能不同的平台不同,也可能不需要

mkdir -p /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/cp $RPM_BUILD_DIR/%{name}-%{version}/%{name} /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/

文件全部完成后,tar,并rpmbuild检查结果

tar -czvf helloworld-0.1.tar.gz helloworld-0.1/cp helloworld-0.1.tar.gz /root/rpmbuild/SOURCESrpmbuild -ba helloworld.spec

git patch应用到rpmbuild

主要是git库可以方便的管理文件,并生成patch文件(这里都是本地操作,所以git push这种命令是没有的,用户配置也不需要,你只需要一个高版本的git)

这里写图片描述

这里写图片描述

这里写图片描述

修改helloworld.c后并提交
这里写图片描述

生成patch

确定git版本是支持 git format-patch命令的,下面是我用windows的实验(我的虚拟机centos没装好高版本的git)

仍然是两个提交日志

这里写图片描述

生成最近的两个patch文件

git format-patch -2 

这里写图片描述

可以直接查看patch文件,linux下可以直接vim打开
这里写图片描述

如下把 0002-fix-bug.patch 打上,重新生成rpm

  • 1 先把 0002-fix-bug.patch 文件复制到/root/rpmbuild/SOURCES下面,与原来的helloworld-0.1.tar.gz一起

  • 2 修改helloworld.spec文件,修改后的文件如下

注意打patch的位置

Summary:the first rpmName:helloworldVersion:0.1Release:1%{?dist}Vendor:johnLicense:ShareGroup:Applications/TextSource0:%{name}-%{version}.tar.gz# add patchPatch1:0002-fix-bug.patch%descriptionhelloworld.rpm build test%prepexport RPM_SOURCES_DIR=/root/rpmbuild/SOURCESexport RPM_BUILD_DIR=/root/rpmbuild/BUILDtar -xzvf $RPM_SOURCES_DIR/%{name}-%{version}.tar.gz%setup%patch1 -p1%buildcd $RPM_BUILD_DIR/%{name}-%{version}./configuremake%installcd $RPM_BUILD_DIR/%{name}-%{version}make installmkdir -p /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/cp $RPM_BUILD_DIR/%{name}-%{version}/%{name} /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/%cleanrm -rf $RPM_BUILD_DIR/%{name}-%{version}%files%defattr(-,root,root)/usr/bin/%{name}%doc $RPM_BUILD_DIR/%{name}-%{version}/readme
  • 3 rpmbuild -ba helloworld.spec ,并验证

这里写图片描述