I think you can do this with git clone --single-branch
:
--[no-]single-branch
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. When creating a shallow clone with the --depth option, this
is the default, unless --no-single-branch is given to fetch the
histories near the tips of all branches. Further fetches into the
resulting repository will only update the remote-tracking branch for the
branch this option was used for the initial cloning. If the HEAD at the
remote did not point at any branch when --single-branch clone was made,
no remote-tracking branch is created.
Note that this says you need a branch to be specified with --branch
, rather than a tag. However, the documentation for --branch
says:
--branch , -b
Instead of pointing the newly created HEAD to the branch pointed to by
the cloned repository’s HEAD, point to branch instead. In a
non-bare repository, this is the branch that will be checked out.
--branch can also take tags and detaches the HEAD at that commit in the
resulting repository.
The last sentence says you can use --branch
with a tag. The only thing I'm not sure of is whether you can both use --single-branch
and pass a tag to --branch
. I guess you will have to try that to confirm. Alternatively, you will have to create a branch in the remote repository as opposed to a tag.
Update
You now say you also want to destroy the entire history. Do this afterwards.
Two ways:
Living dangerously:
git clean -xdf # Clean out everything not in git
rm -rf .git # remove git
git init . # put it back
git add . # Add all the files
git commit -a -m "Eternal sunshine of the spotless mind"
Living less dangerously
git rebase --root -i # needs recent version of git
then change every line to begin with s
to squash into the original commit.
Also see How to squash all git commits into one?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…