你不能,除非通过你已经在考虑的方法。
具体来说,转every提交到 zip 存档(每次提交一个单独的存档),只需迭代每个提交,将每个提交转换为 zip 存档。
您的迭代方法只需要遍历所有可能的提交,而不是仅遍历该对象的所有第一父母master
分支,并且您必须使用git archive
在每次这样的提交上。因此:
git rev-list --all |
while read hash; do git archive ...options... $hash
done
命令git rev-list --all
告诉 Git 按某种顺序打印出每个可到达的提交哈希 ID。要更改顺序,请使用两者可用的各种排序选项git rev-list
and git log
(e.g., --author-date-order
or --topo-order
).
If you don't想要每一次提交——如果你只想要 master 的第一父母——你仍然可以这样做git rev-list
:
git rev-list --first-parent master | ...
在这里,由于 Git 只从任何一次提交开始遍历第一父母master
标识,哈希 ID 将以 Git 认为的正向顺序输出,即向后穿过分支的第一个父级:
...--o--o--o--o--o--o------o <-- master
\ \ /
\ X--X--...X <-- somebranch
\ /
X--X----X--X <-- anotherbranch
没有任何一个X
提交将会出现,因为它们不在第一父系上。 (没有--first-parent
,因为所有提交somebranch
,以及除最后一个之外的所有anotherbranch
, are also on master
,你会得到所有X
承诺。)
[Basj 添加了以下内容,这似乎是 bash 特定的,因为$((i=i+1))
:] 编辑:这是一个随时可用的命令,可以按照问题中的描述执行此操作:
git rev-list --all --reverse | while read hash; do git archive --format zip --output ../myproject-commit$((i=i+1))-$hash.zip $hash; done
[torek 觉得需要添加:-) :请注意,上面按顺序枚举提交,即使这不是可逆映射。]