Skip to content Skip to footer
0 items - $0.00 0

Git clone –depth 2 is vastly better than –depth 1 if you want to Git push later by jakub_g

Git clone –depth 2 is vastly better than –depth 1 if you want to Git push later by jakub_g

Git clone –depth 2 is vastly better than –depth 1 if you want to Git push later by jakub_g

12 Comments

  • Post Author
    rafaelcosta
    Posted February 12, 2025 at 9:32 am

    I'm wondering what the "because when we read it in, we mangle it" part really means… does this mean that there's no way to reference the commit (signaling that it's just a reference and has no actual data) without actually reading the contents of it?

    — Update: just realized why it wouldn't make sense: `git push` would send only the delta from the previous commit and the previous commit is… non-existent (we only know it's ID), so we'd be back in square 1 (sending everything).

  • Post Author
    edflsafoiewq
    Posted February 12, 2025 at 9:36 am

    Do blobless clones suffer from this?

  • Post Author
    necovek
    Posted February 12, 2025 at 10:32 am

    I like the fact that none of this was tested, even if described with such authority :)

    Anyone try it out yet?

    (Not that I don't trust it, but I usually fetch the full history locally anyway)

  • Post Author
    nopurpose
    Posted February 12, 2025 at 10:50 am

    `git clone –filter blob:none` FTW

  • Post Author
    Timwi
    Posted February 12, 2025 at 10:55 am

    This seems like a bug to me. Even if the previous commit is “mangled” as they call it, there's no reason why you can't diff against it and only send the diff.

  • Post Author
    haunter
    Posted February 12, 2025 at 11:18 am

    Wait is this a bug actually?

  • Post Author
    jbreckmckye
    Posted February 12, 2025 at 11:18 am

    Why can't git push, when it encounters a `.git/shallow`, just ask the git server to fill in the remaining history by verifying the parent hashes the client can send?

  • Post Author
    zeristor
    Posted February 12, 2025 at 11:46 am

    Should have the (2021) suffix

  • Post Author
    bradley13
    Posted February 12, 2025 at 11:48 am

    Ok, I'm a simplistic Git user, but: I always do a full clone. Maybe (probably) I will never need all that history, but…maybe I will. Disk space is cheap.

  • Post Author
    mg
    Posted February 12, 2025 at 11:52 am

    Reading this again reminds me of the fact how beautifully git uses the file system as a database. Where everything is laid out nicely in directories and files.

    Except for performance, is there any downside to this?

    In other words: When you store data in an application that only reads and writes data occasionally, is it a good idea to use the git approach and store it in files?

  • Post Author
    wvh
    Posted February 12, 2025 at 12:18 pm

    That's a beautiful answer. Sometimes people explain something you already know, but different parts of your brain light up. This doesn't just explain git once more, but also plants some seeds related to hashed state optimisations in other, future challenges.

  • Post Author
    kruador
    Posted February 12, 2025 at 1:03 pm

    It isn't mangled. The commit is there as-is. Instead the repository has a file, ".git/shallow", which tells it not to look for the parents of any commit listed there. If you do a '–depth 1' clone, the file will list the single commit that was retrieved.

    This is similar to the 'grafts' feature. Indeed 'git log' says 'grafted'.

    You can test this using "git cat-file -p" with the commit that got retrieved, to print the raw object.

    > git clone –depth 1 https://github.com/git/git
    > git log

    commit 388218fac77d0405a5083cd4b4ee20f6694609c3 (grafted, HEAD -> master, origin/master, origin/HEAD)
    Author: Junio C Hamano <gitster@pobox.com>
    Date: Mon Feb 10 10:18:17 2025 -0800

        The ninth batch
    
        Signed-off-by: Junio C Hamano <gitster@pobox.com>
    

    > git cat-file -p 388218fac77d0405a5083cd4b4ee20f6694609c3

    tree fc620998515e75437810cb1ba80e9b5173458d1c
    parent 50e1821529fd0a096fe03f137eab143b31e8ef55
    author Junio C Hamano <gitster@pobox.com> 1739211497 -0800
    committer Junio C Hamano <gitster@pobox.com> 1739211512 -0800

    The ninth batch

    Signed-off-by: Junio C Hamano <gitster@pobox.com>

    I can't reproduce the problem pushing to Bitbucket, using the most recent Git for Windows (2.47.1.windows.2). It only sent 3 objects (which would be the blob of the new file, the tree object containing the new file, and the commit object describing the tree), not the 6000+ in the repository I tested it on.

    It may be that there was a bug that has now been fixed. Or it may be something that only happens/happened with GitHub (i.e. a bug at the receiving end, not the sending one!)

    I note that the Stack Overflow user who wrote the answer left a comment underneath saying

    "worth noting: I haven't tested this; it's just some simple applied math. One clone-and-push will tell you if I was right. :-)"

Leave a comment

In the Shadows of Innovation”

© 2025 HackTech.info. All Rights Reserved.

Sign Up to Our Newsletter

Be the first to know the latest updates

Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.