使用方法:

git diff ${old-commit} ${new-commit}  > commit-operation.patch

OR

git format-patch --stdout - b1af44f > commit-operation.patch (recommend)

THEN 

git apply commit-operation.patch

git 帮助信息:

git format-patch  -h
usage: git format-patch [<options>] [<since> | <revision-range>] -n, --numbered use [PATCH n/m] even with a single patch
-N, --no-numbered use [PATCH] even with multiple patches
-s, --signoff add Signed-off-by:
--stdout print patches to standard out
--cover-letter generate a cover letter
--numbered-files use simple number sequence for output file names
--suffix <sfx> use <sfx> instead of '.patch'
--start-number <n> start numbering patches at <n> instead of
-v, --reroll-count <n>
mark the series as Nth re-roll
--rfc Use [RFC PATCH] instead of [PATCH]
--subject-prefix <prefix>
Use [<prefix>] instead of [PATCH]
-o, --output-directory <dir>
store resulting files in <dir>
-k, --keep-subject don't strip/add [PATCH]
--no-binary don't output binary diffs
--zero-commit output all-zero hash in From header
--ignore-if-in-upstream
don't include a patch matching a commit upstream
-p, --no-stat show patch format instead of default (patch + stat) Messaging
--add-header <header>
add email header
--to <email> add To: header
--cc <email> add Cc: header
--from[=<ident>] set From address to <ident> (or committer ident if absent)
--in-reply-to <message-id>
make first mail a reply to <message-id>
--attach[=<boundary>]
attach the patch
--inline[=<boundary>]
inline the patch
--thread[=<style>] enable message threading, styles: shallow, deep
--signature <signature>
add a signature
--base <base-commit> add prerequisite tree info to the patch series
--signature-file <file>
add a signature from a file
-q, --quiet don't print the patch filenames

git 变量KV命名:

git -h
Unknown option: -h
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]

# For Example
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree format-patch --stdout - b1af44f > commit-operation.patch

3.两种patch的比较:

  • 兼容性:很明显,git diff生成的Patch兼容性强。如果你在修改的代码的官方版本库不是Git管理的版本库,那么你必须使用git diff生成的patch才能让你的代码被项目的维护人接受。
  • 除错功能:对于git diff生成的patch,你可以用git apply --check 查看补丁是否能够干净顺利地应用到当前分支中;如果git format-patch 生成的补丁不能打到当前分支,git am会给出提示,并协助你完成打补丁工作,你也可以使用git am -3进行三方合并,详细的做法可以参考git手册或者《Progit》。从这一点上看,两者除错功能都很强。
  • 版本库信息:由于git format-patch生成的补丁中含有这个补丁开发者的名字,因此在应用补丁时,这个名字会被记录进版本库,显然,这样做是恰当的。因此,目前使用Git的开源社区往往建议大家使用format-patch生成补丁。
 
 

git-format-patch的更多相关文章

  1. git diff 生成patch, git apply patch 打补丁方法说明,以及分支管理的简单操作。

    git diff 简易操作说明 先git log 查看commit ID, 记录你想要打的补丁的ID 比如说: git log commit 4ff35d800fa62123a28b7bda2a04e ...

  2. Git的Patch功能

    转自:http://www.cnblogs.com/y041039/articles/2411600.html UNIX世界的软件开发大多都是协作式的,因此,Patch(补丁)是一个相当重要的东西,因 ...

  3. git 生成patch 和打入patch

    转载:https://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用gi ...

  4. 如何使用git 生成patch 和打入patch【转】

    本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用 ...

  5. 如何使用git 生成patch 和打入patch 标签: gitpatch【转】

    本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用 ...

  6. git diff patch方法

    UNIX世界的软件开发大多都是协作式的,因此,Patch(补丁)是一个相当重要的东西,因为几乎所有的大型UNIX项目的普通贡献者,都是通过 Patch来提交代码的.作为最重要的开源项目之一,Linux ...

  7. [Git] Use git add --patch for better commit history and mitigating bugs

    Let's split our changes into separate commits. We'll be able to check over our changes before stagin ...

  8. git diff patch

    如何生成patch:修改一个地方,然后git diff > xxx.patch 就会生成一个patch文件,这里的关键似乎是, 源文件的某个模块的版本要和线上发布的最新版本要一致,这样patch ...

  9. git 生成patch和打patch

    有这样的 目录层次 x/xx/xxx/xxx/ttt.c而 我的 当前位置 是在 x/下 ,执行git diff> test.patch 在test.patch补丁文件里的路径信息是这样的:- ...

  10. git 生成patch和应用patch【转】

    本文转载自:http://www.jianshu.com/p/814fb6606734 1.在git源码目录下执行 1.1.两个commit间的修改(包含两个commit) git format-pa ...

随机推荐

  1. python中的GIL详解

    GIL是什么 首先需要明确的一点是GIL并不是Python的特性,它是在实现Python解析器(CPython)时所引入的一个概念.就好比C++是一套语言(语法)标准,但是可以用不同的编译器来编译成可 ...

  2. react-router(v4) 路由跳转后返回页面顶部问题

    遇到的问题 由A页面跳转到B页面,B页面停留在A页面的位置,没有返回到顶部. 问题分析 首先分析下出现此问题的原因: 在项目中使用的是 hashHistory,它是建立在 history 之上的,当路 ...

  3. Factorized TDNN(因子分解TDNN,TDNN-F)

    论文 Povey, D., Cheng, G., Wang, Y., Li, K., Xu, H., Yarmohamadi, M., & Khudanpur, S. (2018). Semi ...

  4. 2018-2019-1 20165234 实现mypwd

    实现mypwd(选做,加分) 1 学习pwd命令 2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3 实现mypwd 4 测试mypwd 提交过程博客的链接

  5. Flow Problem

    Flow Problem TimeLimit:5000MS  MemoryLimit:32768KB 64-bit integer IO format:%I64d   Problem Descript ...

  6. css杂项补充

    css杂项补充 一.块与内联 1.块 独行显示 支持宽高,宽度默认适应父级,高度默认由子级或内容撑开 设置宽高后,采用设置的宽高 2.内联 同行显示 不支持宽高 margin上下无效果,左右会起作用, ...

  7. LVS前奏-ARP知识回顾

    什么是ARP协议: ARP协议,全称“Address Resolution Protocol”(地址解析协议),使用ARP协议,可以实现将IP地址解析成对应主机的物理地址(MAC地址) 为了能够正确的 ...

  8. SpringBoot 多数据源分布式事务

    1.pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  9. 在Windows环境下搭建Nginx文件服务器(简单实用版)

    为了解决项目组内容应用,打算把本地的e:tools目录共享出来,具体操作步骤如下1.下载安装包:http://nginx.org/download/nginx-1.9.15.zip2.解压缩3.修改配 ...

  10. Java Spring Boot VS .NetCore (二)实现一个过滤器Filter

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...