如何将软件的commit制作成patch并打入到源代码中,此处以glibc为例

下载源码

git clone https://github.com/bminor/glibc.git

切到出问题的分支

git checkout openEuler-22.03-LTS-SP4_update20240819
git log --oneline --graph

找在这个分支上提交的commit

[root@host-192-168-0-169 glibc]# git log --oneline openEuler-22.03-LTS-SP4-release..openEuler-22.03-LTS-SP4_update20240819 --graph
* 2291cb1 (tag: openEuler-22.03-LTS-SP4_update20240819) enable share library use huge page for aarch architecture
*   4a23394 !863 mktime: improve heuristic for ca-1986 Indiana DST
|\  
| * c5118dc mktime: improve heuristic for ca-1986 Indiana DST
|/  
*   6e2f182 !858 [sync] PR-854: resolv:Do not wait for no-existing second DNS response after error
|\  
| * 8037b57 fix bug
|/  
*   c03a27c !856 [sync] PR-852: stdlib: fix grouping verification with multi-byte thousands
|\  
| * 107f774 stdlib: fix grouping verification with multi-byte thousands
|/  
* adfa6cb !850 [PATCH] Check the validity of len before mmap
* 427e426 [PATCH] Check the validity of len before mmap

复制commit的hash值进行制作patch包

[root@host-192-168-0-169 glibc]# git format-patch 427e426..4a23394   #一个范围的提交制作成补丁
0001-stdlib-fix-grouping-verification-with-multi-byte-tho.patch
0002-fix-bug.patch
0003-mktime-improve-heuristic-for-ca-1986-Indiana-DST.patch

进入源代码路径,打入patch

# 检查patch能否正常应用
# 不应用修补程序,而是输出diffstat作为输入
git apply --stat xxx.patch

# 不应用修补程序,而是查看修补程序是否适用
git apply --check xxx.patch

# 应用补丁
patch -p1 < xxx.patch

# 也可以这样应用补丁
patch apply xxx.patch

把源代码进行编译(略)

results matching ""

    No results matching ""