1

I have a git repo (local) and I need to un-git it so that each commit is stored in a folder and there is no sign of git. So it should result in folders of my branches and inside these folders folders representing each commit.

Is this possible?

0

1 Answer 1

4

Well, something like this:

n=0
git rev-list --reverse HEAD | while read rev; do
  n=$(expr $n + 1)
  dir="$n-$rev"
  mkdir "$dir"
  git archive --format=tar "$rev" | ( cd $dir && tar xvf - )
done

This will put the revisions into folders numbered "1-hash", "2-hash" etc. (change the formula to calculate dir as appropriate).

Also this only works for "HEAD"... it's hard to come up with a numbering scheme if you need all the branches, and hard to know what to call the directories otherwise. Although you could simply use git rev-list --branches and then calculate dir as $(git name-rev "$rev")

Ideally you would be able to extract the files using hard links to represent identical content, but that would be quite a bit more work!

2
  • I was thinking you could simplify this a lot with git filter-branch --tree-filter. It starts each filter in the root of a checkout of that revision. You could make the filter cp -a . somewhere-based-on-rev Commented Jan 3, 2011 at 22:06
  • That's not really simpler, imho. Mind you, I wrote the above as a one-liner, then expanded it for clarity and added the revision numbering... not everyone is that comfortable with sh I guess. Also, using "git archive" and tar works from a bare repo, just set the GIT_DIR environment variable.
    – araqnid
    Commented Jan 3, 2011 at 22:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.