git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Question on shallow clones.

From
Duy Nguyen <pclouds@gmail.com>
Date
Feb 24, 2015, 09:33 UTC
Message-ID
<CACsJy8BECAo-ekv0TSYMY2dOwVuQ-d4ak_Rofxunz=WKDFcSyw@mail.gmail.com>
In-Reply-To
<40B70861-177F-4239-A86F-49C92121ACE7@mu.org>
On Fri, Feb 20, 2015 at 9:13 PM, Alfred Perlstein <bright@mu.org> wrote:
Show 16 quoted lines
> Hello,
>
> Very sorry if this has been explained before, I have been doing research past few weeks in spare time and have not found a good answer yet on the safety of doing something with git.
>
> Basically we have some repos with huge history, namely FreeBSD source and FreeBSD ports.  In order to reduce the space in $repo/.git as well as speed up clone time we were thinking of doing a shallow clone of the repo with something like --depth 5000.
>
> I am wondering, if we such a thing, basically:
>
> # get a shallow mirror of let's say 5000 entries
> git clone --depth 5000 --mirror our-freebsd.git  smaller-freebsd.git
> # move our current repo to a backup
> mv our-freebsd.git our-freebsd.git.backup
> # make shallow repo our primary
> mv smaller-freebsd.git our-freebsd.git
>
> Will we be able to push/pull from our "new" repo as if nothing happened?  Will hashes remain the same?

Yes (except the following) and yes if you use git 1.9.0 or later on both client and server sides. The support in 1.9.0 targets this exact use case (among others).

- Pushes that require updating $GIT_DIR/shallow (i.e. change the
history cut points, perhaps adding more of them) on server are
rejected by default, unless you set receive.shallowupdate. Normal
pushes should go through fine though.
- Because of the shortened history, found merge bases could be less
ideal than from a full clone. This may cause some more merge
conflicts.
Show 14 quoted lines
> Can we in theory later do this:
>
> # merge branches from the "github" remote and push back to "our-freebsd.git"
> git clone /url/our-freebsd.git  our-freebsd.git
> cd our-freebsd.git
> git remote add github https://github.com/freebsd/freebsd.git
> git fetch github
> # get from our-freebsd
> git checkout -b master origin/master
> # now merge in freebsd changes
> git merge --no-ff github/master
> git push origin HEAD
>
> Or will this break terribly?

I'm not sure which repo is shallow, which is full (or both are shallow?), Regardless, I don't see problems with this. If it breaks, it's a bug.

-- 
Duy
Previous: Alfred Perlstein
Message 2 of 2 in “Question on shallow clones.”
  1. Alfred PerlsteinFeb 20, 2015
  2. Duy NguyenFeb 24, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.