将所有提交导出到ZIP文件或目录 [英] Export all commits into ZIP files or directories

查看:55
本文介绍了将所有提交导出到ZIP文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将所有提交导出到ZIP文件(不仅包含补丁/差异,还包含所有文件):

How is it possible to export all commits into ZIP files (containing all files, not only patch/diff):

myproject-commit1-67d91ab.zip
myproject-commit2-9283acd.zip
myproject-commit3-c57daa6.zip
...

或进入目录:

myproject-commit1-67d91ab/
myproject-commit2-9283acd/
myproject-commit3-c57daa6/

?

我正在考虑以下命令:

git archive --format zip --output myproject-commit3.zip c57daa6

来自如何使用以下命令导出特定提交git-archive?,但是如何获取所有提交?

注意:

  • 目标是对每个提交的所有文件进行导出,这样即使我没有 git ,我也可以访问它们在机器上

  • the goal is to do an export of all files of each commit, so that I can have access to them even if I don't have git on the machine

the answer from How can I export Git change sets from one repository to another via sneaker net (external files)? creates a .bundle file, but it seems impossible to access it without git, so it's not what I'm looking for

这几乎可行:

for ((i = 0;; ++i)); do git checkout master~$i || break; tar czf ../myproject-commit$i.tgz .; done

但它还会存档当前目录中所有不是的文件 git add ed到仓库...如何避免这个问题?

but it also archives all the files in the current directory which are not git added to the repo... How to avoid this problem?

推荐答案

除了已经在考虑的方法之外,您不能这样做.

You can't, except by the methods you are already thinking about.

具体来说,要将每个提交都转换为zip存档(每个提交一个单独的存档),只需对每个提交进行迭代,然后将每个提交均转换为zip存档.

Specifically, to turn every commit into a zip archive (one separate archive per commit), simply iterate over every commit, turning each one into a zip archive.

您的迭代方法只需要遍历所有可能的提交,而不是仅遍历 master 分支的所有第一级父母,并且您必须在每个上使用 git archive 这样的承诺.因此:

Your method for iterating simply needs to walk all possible commits, rather than walking only all first-parents of the master branch, and you must use git archive on each such commit. Hence:

git rev-list --all |
    while read hash; do git archive ...options... $hash
done

命令 git rev-list --all 告诉Git以某种顺序打印出每个可到达的提交哈希ID.要更改顺序,请使用 git rev-list git log 可用的各种排序选项(例如,-author-date-order -topo-order ).

The command git rev-list --all tells Git to print out every reachable commit hash ID, in some order. To change the order, use the various sorting options available to both git rev-list and git log (e.g., --author-date-order or --topo-order).

如果您不希望进行每一次提交(如果您只希望母版的第一代父母),您仍然可以使用 git rev-list 来做到这一点:

If you don't want every commit—if you want instead only first-parents of master—you can still do this with git rev-list:

git rev-list --first-parent master | ...

在这里,由于Git仅从任何提交 master 所标识的父母开始走动,所以哈希ID将以Git认为的前向顺序输出,即,在分支的第一对父母之间是向后的:

Here, since Git is walking only first-parents starting from whichever commit master identifies, the hash IDs will be output in what Git considers forward order, i.e., backwards across the branch's first-parents:

...--o--o--o--o--o--o------o   <-- master
      \        \          /
       \        X--X--...X   <-- somebranch
        \         /
         X--X----X--X   <-- anotherbranch

X 提交都不会出现,因为它们不在第一对父系血统中.(没有-first-parent ,因为 somebranch 上的所有提交以及 otherbranch 上除最后一个以外的所有提交都为 master 上,您将获得所有 X 提交.)

None of the X commits will appear since they are not on the first-parent lineage. (Without --first-parent, since all the commits on somebranch, and all but the last one on anotherbranch, are also on master, you would get all the X commits.)

[Basj添加了以下内容,由于 $((i = i + 1)),它似乎是bash特有的:]这是一个随时可以使用的命令,其用法如下:问题中描述的内容:

[Basj adds the following, which appears to be bash-specific due to $((i=i+1)):] this is a ready to use command to do it as described in the question:

git rev-list --all --reverse | while read hash; do git archive --format zip --output ../myproject-commit$((i=i+1))-$hash.zip $hash; done

[torek觉得有必要添加:-):请注意,即使这不是可逆的映射,上面的操作也会按顺序枚举提交.]

[torek feels the need to add :-) : Note that the above enumerates commits sequentially, even if this is not an invertible mapping.]

这篇关于将所有提交导出到ZIP文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆