0

I've an existing git repo (existingrepo). Now I want to create a new git repo (newrepo) that will contain only certain tagged/release versions.

For example,

existingrepo v0.1
existingrepo v0.2
existingrepo v1.0 
existingrepo v1.1
existingrepo v1.2
existingrepo v1.3 
existingrepo v2.0

newrepo    v1.0
newrepo    v2.0 

What is the recommended way for achieving this in git?

3
  • Create newrepo by cloning existingrepo and, in the clone, use interactive rebase to only keep the commits of interest.
    – jub0bs
    Jan 22, 2015 at 14:02
  • @Jubobs A better approach might be to loop over all the versions (presumably tags), use git archive to create a zip/tar-file of that version that you then unpack into newrepo and commit with an appropriate commit message. I'd hate to have to use interactive rebase to select a dozen commits out of a thousand, and squash all the rest...
    – twalberg
    Jan 22, 2015 at 14:58
  • @twalberg I wouldn't know about that. I agree that, with a large total number of commits, my approach may prove unwieldy; however, if you use a good text editor and the number of commits to keep is small, it should be no hassle.
    – jub0bs
    Jan 22, 2015 at 15:09

1 Answer 1

2

I would take this approach, assuming all versions you are interested in have associated tags:

cd existingrepo
for v in $(<list_of_versions.txt)
do
  git archive --format=tar "refs/tags/${v}" | (cd newrepo; git rm -rf *; tar xpf -)
  (cd newrepo; git add -A .; git commit -m "Import of version ${v}"; git tag "${v}")
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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