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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值