From: Chris Jerdonek <chris.jerdonek@gmail.com>
To: git@vger.kernel.org
Subject: git-clone --single-branch clones objects outside of branch
Date: Sun, 26 Jan 2020 04:39:52 -0800 [thread overview]
Message-ID: <CAOTb1wfoMf338VPRYcjAv+EaMYQxKJ=kP6-qMykG-LfxPrWuag@mail.gmail.com> (raw)
Hi,
I'm reporting some git-clone behavior regarding --single-branch that I
found unexpected after reading the docs. I'm using git 2.25.0.
The git-clone docs for --single-branch say:
> Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at.
(from: https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---no-single-branch
)
However, when I attempted this with a local repo, I found that objects
located only in branches other than the branch I specified are also
cloned. Also, this is true even if the remote repo has only loose
objects (i.e. no pack files). So it doesn't appear to be doing this
only to avoid creating new files.
In contrast, git-fetch behaves as expected (including locally).
git-fetch appears to fetch only objects in the given branch, when a
branch is specified.
Below are some commands to assist with reproducing this situation (but
you will need to update the path in the `git-remote add` invocation
below). At the least, it seems like the docs should clarify the
behavior. (The Python commands were for when I was doing some
experiments with pack files.)
mkdir repo1
cd repo1
git init
python -c "print('a\n' + 10 * 'x\n')" > a.txt
git add a.txt
git commit -m "add a"
# Get object id to check existence with `git cat-file -t` below.
git hash-object a.txt
git checkout -b dev
python -c "print('b\n' + 10 * 'x\n')" > b.txt
git add b.txt
git commit -m "add b"
# Get object id to check existence with `git cat-file -t` below.
git hash-object b.txt
git checkout master
cd ..
mkdir repo2
cd repo2
git init
git remote add other file:///<path-to-repo1>
git fetch other master
cd ..
git clone --branch master --single-branch repo1 repo3
Thanks,
--Chris
next reply other threads:[~2020-01-26 12:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-26 12:39 Chris Jerdonek [this message]
2020-01-27 5:55 ` git-clone --single-branch clones objects outside of branch Jeff King
2020-01-27 6:46 ` Chris Jerdonek
2020-01-28 9:48 ` Jeff King
2020-01-29 1:59 ` Chris Jerdonek
2020-01-29 2:23 ` Jeff King
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='CAOTb1wfoMf338VPRYcjAv+EaMYQxKJ=kP6-qMykG-LfxPrWuag@mail.gmail.com' \
--to=chris.jerdonek@gmail.com \
--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).