我希望获得对文件/文件夹进行的所有提交的补丁。
我可以通过git log --format="%H"-- path/to/folder
有没有办法可以从这个列表中生成补丁。
[编辑]:
以下代码部分解决了我的问题
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的补丁,我将失去补丁的顺序。有没有更好的解决方案
答案 0 :(得分:2)
你可以尝试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 for a single file
中的示例所以试试这个:
get format-patch from..to -o patches /path/to/file
答案 1 :(得分:2)
想出下面的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
答案 2 :(得分:0)
我仅使用 git
进行的轻微即兴创作(刚作曲):
git format-patch $(git rev-list --max-parents=0 HEAD)..HEAD -- path/to/file
如果 rev-list --max-parents
返回多个提交,则可能不起作用。使用了该帖子中的想法: