git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Ben Lau <benlau@ust.hk>
Cc: git@vger.kernel.org
Subject: Re: Clone a repository with only the objects needed for a single tag
Date: Tue, 01 Nov 2005 23:01:41 -0800	[thread overview]
Message-ID: <7vy847y1m2.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <43681E47.4010203@ust.hk> (Ben Lau's message of "Wed, 02 Nov 2005 10:02:47 +0800")

Ben Lau <benlau@ust.hk> writes:

>   Is there any method to clone/copy a repository with only the
> objects needed for a single tag in order to save disk space?
>   For example, if I want to start a new project based on a
> specific version of kernel like v2.6.14. I would run
> `git-clone` and then checkout a new branch based on the tag.

Depends on what you want to do in that shallow copy.

If the only thing you would want to do is to build it, then you
could 'git-tar-tree v2.6.14' and extract that on your notebook.
The output is just a tar so there will no history, though.

If you want to develop while on the road, but do not
particularly need to be able to inspect the history beyond the
point you started, you could create a deliberately broken
repository, using the git-shallow-clone script (attached), like
this:

    $ git clone -n $mothership satellite
    $ cd satellite
    $ git-shallow-pack --all
    $ rm -f .git/objects/pack/pack-*
    $ mv pack-* .git/objects/pack/.

If the original repository you are cloning from is local, you
could instead do:

    $ git clone -l -s -n $mothership satellite
    $ cd satellite
    $ git-shallow-pack --all
    $ rm .git/objects/info/alternates
    $ mv pack-* .git/objects/pack/.

You could develop in this repository, even build up your own
commit chains, and when you come back you could push from this
repository back to your 'mothership' repository.  In essense,
any operation that does not require you to have full history
should work.

One important thing that would not always work would be to pull
into this repository over git-aware protocols, although pulling
from your 'mothership' repository would probably work most of
the time.

One case that would probably break is if the mothership side
reverted a commit beyond this shallow-pack boundary and then you
try to pull from there.  After the revert, the trees and blobs
in that new commit you will be pulling from the mothership are
likely to be the same as the ones contained in commits before
the shallow clone is made.  Because your satellite repo would
claim to have everything that is reachable from the tip (as of
the time the clone was made) of the branch, you cannot complain
if the mothership side assumes you must have those blobs and
trees and did not send them to you when you pull.

---
#!/bin/sh
# git-shallow-pack

git-rev-parse --revs-only --no-flags --default HEAD "$@" |
while read sha1
do
	echo "$sha1"
	while type=`git-cat-file -t "$sha1"` &&
	      case "$type" in tag) ;; *) break ;; esac
	do
		next=`git-cat-file tag "$sha1" |
			sed -ne 's/^object //p' -e q`
		echo "$next"
		sha1="$next"
	done
	git-rev-parse --verify "$sha1^{tree}" 2>/dev/null &&
	git-ls-tree -r "$sha1" | sed -e 's/^[0-7]* [^ ]* //'
done |
sort -k 1,1 -u |
git-pack-objects pack

  reply	other threads:[~2005-11-02  7:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-02  2:02 Clone a repository with only the objects needed for a single tag Ben Lau
2005-11-02  7:01 ` Junio C Hamano [this message]
2005-11-02  8:27   ` Ben Lau
2005-11-02  8:49     ` Andreas Ericsson
2005-11-02  9:10       ` Ben Lau
2005-11-02  9:20     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vy847y1m2.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=benlau@ust.hk \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).