git 相当于 'hg share'?

git equivalent of 'hg share'?

有没有什么方法可以在 git 中共享存储库的历史记录而无需再次克隆整个文件夹?相当于 Mercurial 的

hg share project project-branch

https://www.mercurial-scm.org/wiki/ShareExtension

如果我理解 hg share 的文档,最接近的 Git 等效项是 git worktree,这是 2.5 版的新功能:

Manage multiple working trees attached to the same repository.

A git repository can support multiple working trees, allowing you to check out more than one branch at a time. With git worktree add a new working tree is associated with the repository. This new working tree is called a "linked working tree" as opposed to the "main working tree" prepared by "git init" or "git clone". A repository has one main working tree (if it’s not a bare repository) and zero or more linked working trees.

我相信它仍处于测试阶段,并且有一个明确的警告不要将它与子模块一起使用。

运行 git worktree add ../some/path/ branch 从存储库创建一个新的工作副本 branch../some/path/ 检出。

可以找到关于这个新命令的更详细的概述 on GitHub's blog

评论太长,所以新的答案:

我发现这个流程在 hg 中是完全正常的 - 而在 git 中是不可能的,对于 worktree 和任何其他命令都不可能,因为它看起来像(?)

3 bash-4.2# cd m/
3 bash-4.2# hg init
3 bash-4.2# cd ..
3 bash-4.2# hg share m pm1
updating working directory
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
3 bash-4.2# hg share m pm2
updating working directory
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
3 bash-4.2# cd pm1/
3 bash-4.2# touch foo
3 bash-4.2# hg add foo
3 bash-4.2# hg commit -m test foo
3 bash-4.2# cd ../pm2/
3 bash-4.2# hg log
changeset:   0:d5e4a426dca0
tag:         tip
user:        xxx
date:        Wed Apr 10 15:32:32 2019 +0200
summary:     test

3 bash-4.2# ls
3 bash-4.2# hg summary
parent: -1:000000000000  (no revision checked out)
branch: default
commit: (clean)
update: 1 new changesets (update)     # <--------------- ! :-)
3 bash-4.2# hg up
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
3 bash-4.2# ls
foo

在 git 他们不支持该流程。 它允许同样的事情只检查一次——他们的理由(不干净的工作树)并不能说服我,因为在 hg 中它也是可能的,正如你所看到的。

也在hg中,要更新分享的你,嗯,更新一下(hg pull)。

在git你必须说:

git fetch origin +refs/heads/*:refs/heads/* --prune