git 可以格式化补丁以便它可以与补丁程序一起使用吗?
我需要从 git 存储库创建简单的补丁,可以使用简单的补丁命令行实用程序应用该补丁。
能做到吗?
I'd need to create simple patches from git repository that can be applied with plain simple patch command line utility.
Can it be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
git diff
生成的补丁由patch
工具正确处理。patch
跳过 git 附加到补丁文件的所有附加信息。要应用补丁,您很可能需要-p1
选项。Patches, that
git diff
yields, are correctly processed bypatch
tool.patch
skips all the additional info git appends to the patch file. To apply the patch you most likely will need-p1
option.接受的答案如下:
我很确定我刚刚遇到了一个这是不正确的情况。
/usr/bin/patch
只是默默地(不报告错误)忽略了我的补丁,包括文件重命名信息,从而破坏了部署(幸运的是,我目前只是测试部署:-) ..我发布这个替代答案是为了提醒其他遇到同样问题的人,因为我挠头了一段时间......而且对 StackOverflow 上答案的评论显然不能包含引号。
具有讽刺意味的是,我刚刚切换到统一 diff 格式来解决这个问题,现在我的部署以不同的方式中断,因为统一 diff 不能代表空文件的创建(例如 __init__.py )。谈论进退两难!
The accepted answer states the following:
I'm pretty sure I just ran into a case where this is incorrect.
/usr/bin/patch
just silently (without reporting an error) ignored my patch including file rename information, thereby breaking a deployment (fortunately I'm only testing the deployment at the moment :-) ...I'm posting this alternative answer as a heads up for other people running into the same problem because I was scratching my head for a while... Also comments to answers on StackOverflow apparently can't contain quotes.
Ironically enough I just now switched to the unified diff format to overcome this problem and now my deployment breaks in a different way because unified diffs can't represent the creation of empty files (e.g.
__init__.py
). Talk about being between a rock and a hard place!