编写GIT扩展允许不同分支/头中的文件共存于同一目录中

发布于 2024-12-10 17:54:47 字数 660 浏览 0 评论 0原文

上一个问题我问是否有人已经编写了一个脚本,允许在同一目录中混合来自多个分支(甚至存储库)的文件,以便它们都可以从适当的来源提交/拉取/等等。

请参阅该帖子,了解为什么在反对之前分割成单独的存储库或分支安排不起作用的情况。

这个问题的答案似乎是不存在这样的脚本。我现在的问题是编写脚本的最佳方法是什么。

1)简单的方法。封装一个简单的 perl 脚本,该脚本在后台检查多个分支并记录哪个文件属于哪个分支,然后简单地将文件复制回来并在后台执行 git 命令。

2)如果可能的话(我不知道)某种低级 git 命令的奇特用法可以直接执行此操作,而无需任何签出。这可能吗?

3) git 代码中的某种低级接口。

2 的明显问题是所有隐藏的结帐和整个事情的丑陋浪费了资源,但我对 2 或 3 的了解不够,不知道它们是否合理可能。

--

我想我的主要问题是是否有低级 git 命令可以将文件检入分支而无需创建检出并将它们检出到随机目录中。如果是这样,我可以使用这些命令直接处理多分支目录中的文件,并完全避免秘密签出。

In a previous question I asked if anyone had already written a script to allow mixing files from multiple branches (or even repos) in the same directory so that they would all get committed/pulled/etc.. from their appropriate origins.

Please see that post for reasons why this isn't a case where splitting into separate repos or branch arrangement would work before objecting.

The answer to that question seems to be that no such script exists. My question now is what is the best way to go about writing the script.

1) The easy way. Wrap a simple perl script that checks multiple branches behind the scenes and keeps a record of which file belongs to which branch and simply copies the files back and executes the git commands behind the scenes.

2) If possible (I dunno) some kind of fancy usage of low level git commands to do this directly without having any checkouts. Is this possible?

3) Some kind of low level interface into the git code.

The obvious problem with 2 is wasting resources with all the hidden checkouts and the ugliness of the whole thing but I don't know enough about 2 or 3 to know if they are reasonably possible.

--

I guess my primary question is whether there are low level git commands to check files into a branch without ever creating a checkout and to check them out into random directories. If so I could just use these commands to directly work with the files in my multi-branch directory and avoid secret checkouts entierly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扬花落满肩 2024-12-17 17:54:47

Git 社区书籍的这一章您可能会对低级 Git 交互感兴趣。

换言之,

  1. 使用 git hash-object 从文件创建 blob。
  2. 使用 git mktree 从 blob 创建一棵树。
  3. 使用 git commit-tree 为该树创建提交。
  4. 使用 git update-ref 更新分支以指向该提交。

This chapter of the Git Community Book may be of interest to you for low-level Git interaction.

To paraphrase it,

  1. Create blobs from your files with git hash-object.
  2. Create a tree from your blobs with git mktree.
  3. Create a commit for that tree with git commit-tree.
  4. Update a branch to point to that commit with git update-ref.
慢慢从新开始 2024-12-17 17:54:47

这本质上就是 git-subtree 所做的事情(它是一组简单的脚本)——但在边界之间移动文件的情况下它并不简单。有很多事情它并没有尝试提供帮助,但如果您的用例足够简单或纪律良好,那么可能就足够了。

This is in essence what git-subtree does (it's a simple set of scripts) -- but it's non-trivial in cases of moving files between the boundaries. There's lots of things that it doesn't try to help with, but might well suffice if your use-case is sufficiently simple or well-disciplined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文