git diff --no-prefix and patch

If you want to create a patch file via "git diff" that can be applied using "patch -p0 < patchfile" use the following command:

git diff --no-prefix > patchfile

then apply the patch:
patch -p0 < patchfile

If you have an existing "git diff" patch file that was created without the "--no-prefix" option, you can apply that patch via:

patch -p1 < patchfile

this will ignore the default a/ b/ source prefixes.


范例:

打开 patch 文件, 一开始就看得到 path 的路迳所在.

-p[n] 的 n 值, 只要取消多少条 / 及其左边的路迳.
以 /usr/src/linux 为例,
若 -p0 就是不取消任何路经
-p1 则将 / 取消, 得 usr/src/linux
-p2 则是将 /usr/ 取消, 得 src/linux
再以 src/linux 为例:
-p0 依然为 src/linux
-p1 则为 linux


how to use git diff to get patch:

git pull
git status 
git branch
git branch FLUME-1154
git checkout FLUME-1154
-------Modify file named flume-ng------
git branch
git status
git add flume-ng
git commit -m "FLUME-1154: flume-ng script should first try finding java from PATH and then try using bigtop, instead of vice-versa"
git status 
git diff --no-prefix trunk > /home/leslin/flume-patch/FLUME-1154.patch 


关于如何利用git打补丁的详细介绍: 

http://www.cnblogs.com/y041039/articles/2411600.html


版权声明:本文为linhx原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。