I'd like to clone a repository with a longish history. I'm only interested in a few short-lived not-yet-merged feature branches and master
.
In order to not confuse myself with all that past history and merged branches, I'd like to do a shallow clone starting at a specific commit SHA.
However, so far I've only found documentation on how to do shallow clones that only include the last n
commits (--depth
) resp, the commits since a specific date (--shallow-since
).
Is there a way to specify a shallow-clone starting at a given commit?
Git Clone From Specific Commit ID There is no direct way to clone directly using the commit ID. But you can clone from a git tag. However, you can do the following workaround to perform a clone if it is really necessary. The above steps will make your current HEAD pointing to the specific commit id SHA.
git clone If you only need the specific tag, you can pass the --single-branch flag, which prevents fetching all the branches in the cloned repository. With the --single-branch flag, only the branch/tag specified by the --branch option is cloned. $ git clone -b <tagname> –single-branch <repository> .
There is not, which is kind of a shame since it would be easy for Git to implement.
Usually using --depth
is sufficient: just start with a depth you think is enough, and if it's not, repeatedly fetch with --deepen
or --depth
as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With