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
...
or into directories:
myproject-commit1-67d91ab/
myproject-commit2-9283acd/
myproject-commit3-c57daa6/
?
I was thinking about commands like:
git archive --format zip --output myproject-commit3.zip c57daa6
from How do I export a specific commit with git-archive?, but how to get all commits?
Notes:
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
giton the machinethe answer from How can I export Git change sets from one repository to another via sneaker net (external files)? creates a
.bundlefile, but it seems impossible to access it withoutgit, so it's not what I'm looking forthis nearly works:
for ((i = 0;; ++i)); do git checkout master~$i || break; tar czf ../myproject-commit$i.tgz .; donebut 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.
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.
Your method for iterating simply needs to walk all possible commits, rather than walking only all first-parents of the
masterbranch, and you must usegit archiveon each such commit. Hence:The command
git rev-list --alltells Git to print out every reachable commit hash ID, in some order. To change the order, use the various sorting options available to bothgit rev-listandgit log(e.g.,--author-date-orderor--topo-order).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:Here, since Git is walking only first-parents starting from whichever commit
masteridentifies, the hash IDs will be output in what Git considers forward order, i.e., backwards across the branch's first-parents:None of the
Xcommits will appear since they are not on the first-parent lineage. (Without--first-parent, since all the commits onsomebranch, and all but the last one onanotherbranch, are also onmaster, you would get all theXcommits.)[Basj adds the following, which appears to be bash-specific due to
$((i=i+1)):] Edit: this is a ready to use command to do it as described in the question:[torek feels the need to add :-) : Note that the above enumerates commits sequentially, even if this is not an invertible mapping.]