On Mon, Feb 07, 2011 at 06:20:49PM -0800, Mark (my words) wrote:
> Being new to git, and cvs in general, I lack the vocabulary to describe what
> I want to do. Here’s my best shot at articulating it:
> I have, let's say 10, versions of a file in a git repository that I would
> like to save out as individual files. I thought I had found what I was
> but the linked example returns an error, from the best I can tell git isn’t
> recognizing the --parents switch, so I ripped it out and it only returns the
> current commit.
> But maybe that’s not what I need. I think I need to write a loop that takes
> the diff between each commit and its parent and spits it out as a file until
> the number of revisions I specify is reached.
> Anyone have experience with this?
I would do this like this:
$ git log --pretty=%H HEAD~9..HEAD | (i=0; while read h; do \
git show $h:PATHNAME >/tmp/file~$i; i=$((i+1)); done)
With the real (relative) pathname of the file substituted for PATHNAME.
This will create a bunch of files "file~0", "file~1" etc under /tmp,
each representing the state of the file PATHNAME in the HEAD, one commit
before HEAD etc.
Note that this takes exactly 10 adjacent commits no matter whether the
file of interest changed in any of them (or even present in any of
them); if, instead, you need to see a series of 10 commits in which the
file was changed, you have to supply PATHNAME to the git-log as well,
$ git log --pretty=%H HEAD~9..HEAD PATHNAME | ...
Note that in this case the trick with using a counter to name
destination files might not have much sense and you will want to play
with `git name-rev` for instance.
You received this message because you are subscribed to the Google Groups "Git
for human beings" group.
To post to this group, send email to firstname.lastname@example.org.
To unsubscribe from this group, send email to
For more options, visit this group at