在我的本地文件系统中,我希望只克隆git repo (A)的头部,以便不会将历史记录带到新的git repo (B)中。但是,我希望现在在B中的文件可以获得硬链接的好处,以节省空间。有没有办法做到这一点?一旦repo A发生变化,硬链接是否还有用?
谢谢!
谢谢!
git clone --depth 1 --single-branch
明确警告--depth
在本地克隆中被忽略,并且要使用 file://
。因此,您需要在硬链接和浅克隆之间选择。git clone --single-branch --depth 1 file://old_repo_dir
选项创建克隆。我发现 --depth 1
意味着历史记录的1个项目,因此您将获得最新提交以及其父项(如果是合并,则为其父项)。父项从原始存储库获取提交消息,但是提交消息是错误的,因为实际上提交包含整个树的创建。# at the old repo:
git checkout --orphan tmp-snapshot
git commit -m "Initial commit."
# at the new repo location:
git init
git pull OLD_REPO_DIR tmp-snapshot:master
# back at the old repo:
git branch -D tmp-snapshot # no longer serves a purpose
现在新仓库的master
分支只包含一个提交,其树与旧仓库的树完全相同,且没有任何历史记录。
git commit-tree
的文档以从树创建提交,我无法告诉您确切的语法。git checkout --orphan
后跟 git commit
可以在不使用管道的情况下从树中创建提交。 - user4815162342
git branch -D
命令将其删除。该分支在父存储库中不需要额外的空间,因为它只包含一个指向已经存在于存储库中的树的提交。 - user4815162342--depth
意味着--single-branch
。 - sphakka