git patch生成和使用

前言

由于工作需要,基于源码进行改动的时候经常需要在git分支上打各种各样的patch来解决各种各样的问题。这里总结两种生成patch和打patch的方法。

git diff

这种是Unix下的patch,在git分支下通过git diff命令生成。具体命令如下:

git diff > diff.patch

对于git diff生成的patch,可以用如下两条命令进行merge:

git apply diff.patch

或者

patch -p1 < diff.patch

git format-patch

git专用的patch是通过git format-patch生成的。常用的方法如下:

  1. git format-patch -n (-n代表要生成最近n次提交的patch)
  2. git format-patch commit-id-1 commit-id-2 (生成节点1相对于节点2的patch)

git专门的patch直接通过git am命令merge即可。

git am 0001-....-patch

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 12-27

git patch生成和使用的相关文章

git patch生成方法

先把修改commit掉,然后生产修改patch给提交代码的同事,具体操作步骤如下: 修改代码的同事: git format-patch al821_xxx origin/al821_xxx 会生成:0001-HQ00656135-xxx-al821_xxx.patch这样的patch文件 把这个patch给提交代码的同事 提交代码的同事,执行: git am 0001-HQ00656135-xxx-al821_xxx.patch 然后可以检查这个提交记录有没有问题,如果没有问题 执行git pu

Git Patch使用: 生成,导入,解决冲突

1. Git Patch git patch包括2中: 标准diff 和git format-patch 2. 生成patch 2.1 git diff 生成标准patch 最简单, 但是很多信息没有 git diff > my.diff 2.2 git format-patch 生成git专用patch git format-patch -M master format-patch中包涵diff, git commit, time等等 From c0b96dc1b770c45c49bd2945

git patch 的用法

1使用git format-patch生成所需要的patch:当前分支所有超前master的提交:git format-patch -M master某次提交以后的所有patch:git format-patch 4e16                --4e16指的是commit名从根到指定提交的所有patch:git format-patch                          --root 4e16某两次提交之间的所有patch:git format-patch 365a.

git patch 使用

1使用git format-patch生成所需要的patch:当前分支所有超前master的提交:git format-patch -M master某次提交以后的所有patch:git format-patch 4e16                --4e16指的是commit名从根到指定提交的所有patch:git format-patch                          --root 4e16某两次提交之间的所有patch:git format-patch 365a.

git ssh 生成步骤

Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置. github的SSH配置如下: 一 . 设置Git的user name和email: $ git config --global user.name "xuhaiyan" $ git config --global user.email "[email protected]" 二.生成SSH密钥过程:1.查看是否已经有了ssh密钥:cd ~/.ssh如果没有密钥则

使用Git Bash生成新的ssh key

使用Git Bash生成新的ssh key. $ cd ~  ///保证当前路径在"~"下 $ ssh-keygen -t rsa -C "你的邮箱地址"  ///建议填写自己真实有效的邮箱地址 结果: Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa):   ///不填直接回车 Enter passphrase (empty for no passphrase):   ///输入密

Git基础-生成Patch和使用Patch

1.生成Patch(俗称快照) 先来看看repo manifest 的用法 <1>cd /工作目录/项目目录/.repo/manifests <2>repo manifest -r -o 20170601_LittleCola.xml <3>将快照(.xml文件)push到服务器 a. git status b. git add . c. git commit -m "modify message" d. git push ..... 2.使用Pat

git ,创建生成 making git-svn work on mac tiger

http://www.mikeheijmans.com/2008/04/make-git-svn-work-on-mac-osx-tiger/ After a few hours of googling and pull some hair out, I have finally figured out how to make git-svn work on Mac OSX 10.4 Tiger. If you have installed git on your Mac using mac-p

用git difff 生成补丁

http://stackoverflow.com/questions/1191282/how-to-see-the-changes-between-two-commits-without-commits-in-between you can simply pass the 2 commits to git diff like : -> git diff 0da94be 59ff30c > my.patch -> git apply my.patch