首页 > 其他分享 >【git】代码patch包生成和合入

【git】代码patch包生成和合入

时间:2023-07-08 13:22:21浏览次数:38  
标签:git -- am patch apply commit 合入

patch合入

git am

git am会直接将patch的所有信息打上去,而且不用重新git add和git commit,author也是patch的author而不是打patch的人

常用命令

git am 0001-limit-log-function.patch           # 将名字为0001-limit-log-function.patch的patch打上
git am --signoff 0001-limit-log-function.patch # 添加-s或者--signoff,还可以把自己的名字添加为signed off by信息,作用是注明打patch的人是谁,因为有时打patch的人并不是patch的作者
git am ~/patch-set/*.patch                     # 将路径~/patch-set/*.patch 按照先后顺序打上
git am --abort                                 # 当git am失败时,用以将已经在am过程中打上的patch废弃掉(比如有三个patch,打到第三个patch时有冲突,那么这条命令会把打上的前两个patch丢弃掉,返回没有打patch的状态)
git am --resolved                              # 当git am失败,解决完冲突后,这条命令会接着打patch

如有提示“patch does not apply”,表示patch冲突,手动解决完冲突后,继续合入

git am --continue

或者忽略

git am --skip

或者停止合入

git am --abort

git apply

git apply是将补丁文件应用到代码库中,但不会自动创建提交记录。而且使用git apply可以快速地测试一个补丁,检查它是否会导致任何问题或冲突,但是需要手动创建提交记录来记录这个补丁被应用了。但是git apply并不会将commit message等打上去,打完patch后需要重新git add和git commit。

常用命令

git apply --stat 0001-limit-log-function.patch          # 查看patch的情况
git apply --check 0001-limit-log-function.patch         # 检查patch是否能够打上,如果没有任何输出,则说明无冲突,可以打上

打入patch

git apply xxx.patch

如果git与需要打patch的文件不在一个目录(git 在framework下,patch要打入到frameworks/base/下)

git apply --check --directory=base/ xxx.patch
git apply --directory=base/ xxx.patch

如果有冲突,可以先导出冲突

git apply --reject xxxx.patch

此时在代码工程路径下生成.rej结尾的冲突文件,手动修改完冲突点后

git add 修改文件

然后解决冲突后合入

git am --resolved

patch生成

git format-patch

常用命令

git format-patch HEAD^       #生成最近的1次commit的patch
git format-patch HEAD^^      #生成最近的2次commit的patch
git format-patch HEAD^^^     #生成最近的3次commit的patch
git format-patch HEAD^^^^    #生成最近的4次commit的patch
git format-patch <r1>..<r2>  #生成两个commit间的修改的patch(包含两个commit. <r1>和<r2>都是具体的commit号)
git format-patch -1 <r1>     #生成单个commit的patch
git format-patch <r1>        #生成某commit以来的修改patch(不包含该commit)
git format-patch --root <r1> #生成从根到r1提交的所有patch

git diff

将所有修改文件打包成patch

git diff > test.patch

只生成一个文件的patch

git diff test.c > test.patch











参考文章:

https://zhuanlan.zhihu.com/p/104055075

标签:git,--,am,patch,apply,commit,合入
From: https://www.cnblogs.com/Wangzx000/p/17537058.html

相关文章

  • git 总结
    gitstash视频链接gitstash:工作区已经修改,但是需要在不提交的情况下切换到其他分支,此时可以使用gitstash来存储当前工作区的修改。gitstashpush//将工作区的修改放入一个栈中,此时工作区就变干净了可以push多个修改到栈中可以简写成gitstashgitstashpop//弹......
  • git克隆私有仓库时出现的一些问题
    问题一:remote:Writeaccesstorepositorynotgranted.】fatal:unabletoaccess'https://github.com/CaptainRhett/Digital_Circuit_Experiment_Report.git/':TherequestedURLreturnederror:403使用Fine-grainedpersonalaccesstokens产生的tokens认证时会出现该......
  • git使用
    迁移如果是内网有需要情况下先配置host克隆仓库gitclone-bare仓库地址配置git账号gitconfig--globaluser.name""gitconfig--globaluser.email""删除原公钥 rm-rf~/.ssh重新生成公钥ssh-keygen-trsa-C""-b4096查看公钥cat~/.ssh/id_rsa.pub ......
  • Git代码管理、提交、问题、仓库创建与管理
    第一章、在Github上创建仓库第1节、创建仓库进入https://github.com进入项目仓库:yourrepositories右侧点击:new按钮owner填写仓库名称Description填写项目描述public选择项目公开private选择项目不公开第2节、下载和安装Git客户端下载地址:https://git-scm.com/downloa......
  • ML-for-AGV-Dispatching:run.py解读
    importsimpyfromShopFloorimportCenterimportLearnasLeimportnumpyasnpimportpandasaspdimportpickleimporttimeTask="None"#TestD,TestQ,TestDQN,TestSVM,CollectV,CollectW,TrainQ,TrainDQNTask="TestD"'�......
  • IDEA中git回退历史版本,并删除历史提交记录
    本篇文章主要介绍git在idea中的回退历史版本,适用场景为代码提错分支、正常回退版本都可适用。!!!回退前先检查一下本地分支是否和远程分支对应,否则会失败!!!1,打开idea中git历史提交窗口快捷键alt+9(有改动则是自己改的快捷键)2,选择要回退的版本拷贝版本号。(1),比如我选择回退7月4日10......
  • 如何实现Android studio .gitignore没生效的具体操作步骤
    解决AndroidStudio.gitignore没生效问题简介在使用AndroidStudio开发Android应用时,我们通常会使用版本控制系统Git来管理代码。然而,有时候我们会发现.gitignore文件中定义的忽略规则并没有生效,导致一些不必要的文件被提交到Git仓库中。本文将介绍如何解决这个问题。解决流程......
  • git 本地仓库首次推送到远程
    gitinitgitadd.gitcommit-m'firstcommit'gitremoteadd<远程仓库地址>$gitpushoriginmaster:masterwarning:auto-detectionofhostprovidertooktoolong(>2000ms)warning:seehttps://aka.ms/gcm/autodetectformoreinformation.To......
  • TortoiseGit-合并分支方法
    https://blog.csdn.net/weixin_43553694/article/details/1041184021、首先当前分支“提交”并“推送”到服务器上,比如开发分支dev合并到master上2、右键>“切换分支”到要合并的分支master 3、拉取最新master分支,然后右键选择合并,选择dev分支,勾选合......
  • git 介绍和操作
    git介绍&概述git介绍git概述git代码托管服务常用的git代码托管服务使用码云代码托管服务git常用命令git全局设置安转好git后,在文件夹空白处右击,gitbashhere,在里面输入命令。获取git仓库远程不能在仓库下嵌套仓库。这里提示的账号密码是码云的账户。工......