[英]git sparse checkout with multiple repositories
I am wanting to create a project that borrows from two repositories, sparsely checked out.我想创建一个从两个存储库中借用的项目,很少签出。 However the format of "${GIT_REPO}/info/sparse-checkout" only references a path, not a tree-ish or repo centric path.
然而,“${GIT_REPO}/info/sparse-checkout”的格式只引用了一个路径,而不是一个树状或以 repo 为中心的路径。 Hence I cannot seem to reference a specific branch like within this sparse-checkout file like:
repo::branch:~/path
因此,我似乎无法在此稀疏结帐文件中引用特定分支,例如:
repo::branch:~/path
hence the following does not work for me over multiple repos:因此以下对我来说不适用于多个回购:
git config core.sparseCheckout true
git remote add -f repo1 git://...
git remote add -f repo2 git://...
echo "path/within_repo/to/desired_subdir/*" > .git/info/sparse-checkout
git checkout [<tree-ish>]
... the format of "${GIT_REPO}/info/sparse-checkout" only references a path
... "${GIT_REPO}/info/sparse-checkout" 的格式只引用了一个路径
That's true.确实如此。
git remote add -f repo1 git://...
git 远程添加 -f repo1 git://...
Repositories (and remote names) are not relevant;存储库(和远程名称)不相关; all that matters are commits.
所有重要的是提交。
Hence I cannot seem to reference a specific branch...
因此,我似乎无法引用特定的分支......
Branch names are irrelevant as well.分支名称也无关紧要。 Branch names move and change over time;
分支名称随时间移动和变化; commit hash IDs do not.
提交 hash ID 没有。 Any time you want to be totally specific about some particular commit, use its hash ID.
任何时候您想要完全具体地了解某个特定的提交,请使用它的 hash ID。
It might be nice if the sparse checkout file could be based on the commit, but it can't—at least not easily.如果稀疏签出文件可以基于提交可能会很好,但它不能——至少不容易。 You could:
你可以:
git show commit-specifier : path
);git show commit-specifier : path
);$(git rev-parse --git-dir)/info/sparse-checkout
;$(git rev-parse --git-dir)/info/sparse-checkout
; andwith, perhaps, a fall-back default sparse-checkout file if the file does not exist in the given commit.如果文件在给定的提交中不存在,则可能带有回退的默认稀疏签出文件。
Since commit hash IDs uniquely identify the correct commit, one approach to putting the file into a dedicated branch would be:由于提交 hash ID 唯一标识正确的提交,将文件放入专用分支的一种方法是:
sparse-info
sparse-info
git worktree add
) to create an area in which these files will live;git worktree add
)来创建一个存放这些文件的区域; Then to add a new file, you'd maneuver to the right place, link or copy the sparse checkout data, git add
the file, and git commit
the result.然后要添加一个新文件,您需要移动到正确的位置,链接或复制稀疏的结帐数据,
git add
文件,然后git commit
结果。
Or, you could do all this without a branch, with just a dedicated work-area outside your normal work-tree.或者,您可以在没有分支的情况下完成所有这些操作,只需在正常工作树之外的专用工作区。
Finally, consider writing your own format for your sparse checkout file, and a filter.最后,考虑为稀疏检出文件和过滤器编写自己的格式。 Then it's just a matter of running your filter-generator to create the desired
$GIT_DIR/info/sparse-checkout
contents.然后只需运行您的过滤器生成器即可创建所需的
$GIT_DIR/info/sparse-checkout
内容。
From torek's answer:从托雷克的回答:
write its contents into
$(git rev-parse --git-dir)/info/sparse-checkout
将其内容写入
$(git rev-parse --git-dir)/info/sparse-checkout
Make sure to use Git 2.37 (Q3 2022): " git show:<path>
" ( man ) learned to work better with the sparse-index feature, because of rev-parse
.确保使用 Git 2.37(2022 年第三季度):“
git show:<path>
” ( man )学会了更好地使用稀疏索引功能,因为rev-parse
。
See commit 124b05b , commit 4925adb , commit 561287d , commit a37d144 , commit a9e0a49 (26 Apr 2022) by Derrick Stolee ( derrickstolee
) .请参阅Derrick Stolee (
derrickstolee
) 的 commit 124b05b 、 commit 4925adb 、 commit 561287d 、 commit a37d144 、 commit a9e0a49 (2022 年 4 月 26 日)。
(Merged by Junio C Hamano -- gitster
-- in commit acdeb10 , 20 May 2022) (由Junio C Hamano --
gitster
--在提交 acdeb10中合并,2022 年 5 月 20 日)
rev-parse
: integrate with sparse indexrev-parse
: 与稀疏索引集成Signed-off-by: Derrick Stolee
签字人:Derrick Stolee
It is not obvious that the '
git rev-parse
' ( man ) builtin would use the sparse index, but it is possible to parse paths out of the index using the ":<path>
" syntax.'
git rev-parse
' ( man )内置函数并不明显会使用稀疏索引,但可以使用“:<path>
”语法从索引中解析路径。
The 'git rev-parse
' output is only the OID of the object found at that location, but otherwise behaves similarly to 'git show:<path>
' ( man ) .The '
git rev-parse
' output is only the OID of the object found at that location, but otherwise behaves similarly to 'git show:<path>
' ( man ) .
This includes the failure conditions on directories and the error messages depending on whether a path is in the worktree or not.这包括目录的失败条件和取决于路径是否在工作树中的错误消息。
The only code change required is to change the
command_requires_full_index
setting inbuiltin/rev-parse.c
, and we can re-use many existing 'git show
' tests for the rev-parse case.唯一需要更改的代码是更改
builtin/rev-parse.c
中的command_requires_full_index
设置,我们可以重复使用许多现有的 'git show
' 测试用于 rev-parse 案例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.