我想为对文件/文件夹进行的所有提交获取补丁。
我可以通过git log --format="%H"-- path/to/folder获取commit-id列表
有没有办法让我从这个列表中生成补丁。
编辑
下面的代码部分解决了我的问题
for c in `git log --format="%H" -- path/to/file`;do git format-patch "$c^1".."$c" -o patches ; done
因为format-patch是单独调用的,所以我将获得所有编号为0001-commit-text.patch的补丁,其中我将丢失补丁的顺序。有没有更好的解决方案?
发布于 2018-01-23 19:22:02
您可以尝试git diff initial_commit_id..latest_commit_id > changes.patch
这是基于本文:https://www.lullabot.com/articles/git-best-practices-upgrading-the-patch-process
例如:
git diff ab0b3a55de5..6f5dbbc4187b97更新:如果您将特定文件的路径作为参数提供给format-patch,那么它将只为提交创建包含对该文件的更改的补丁。因此不需要循环和逐个调用format-patch。请参阅format-patch for a single file中的示例
所以试试这个:
get format-patch from..to -o patches /path/to/file 发布于 2018-01-23 19:51:20
想出下面的shell脚本来实现这一点。欢迎任何其他答案。
#!/bin/bash
COUNTER=1;
for c in `git log --format="%H" --reverse -- path/to/file`;do
git format-patch --start-number=$COUNTER "$c^1".."$c" -o patches
let COUNTER=COUNTER+1
done发布于 2021-01-20 01:02:08
我仅使用git进行了轻微的非预置(刚刚合成)
git format-patch $(git rev-list --max-parents=0 HEAD)..HEAD -- path/to/file如果rev-list --max-parents返回多个提交,则可能不起作用。使用了这篇文章中的想法:
https://stackoverflow.com/questions/48400287
复制相似问题