git patch

 

有这样的 目录层次 x/xx/xxx/xxx/ttt.c
而 我的 当前位置 是在 x/下 ,执行git diff> test.patch

在test.patch补丁文件里的路径信息是这样的:
- - - a/xx/xxx/xxx  
+++b/xx/xxx/xxx  

如果 应用 test.patch 的时候的 位置 是在 x/ 下,
那么 执行 patch -p1 < test.patch
--------------------------------------

git diff> test.patch,这是产生patch的方式。
注意,使用git diff产生的patch都应该在执行patch 命令时,指定-p1,当 位置是 【在哪里制作的patch,就在哪里 执行】
或者直接使用git apply test.patch 打补丁,执行 这个 命令的位置 也是<在哪里制作的patch,就在哪里执行此命令>。


生成patch
git diff > file.patch

打patch
patch -p1 < file.patch
git apply file.patch

 

 

posted on 2022-02-21 15:07  tycoon3  阅读(194)  评论(0)    收藏  举报

导航