【问题标题】:How to tell git to ignore certain folders and files during a subtree merge?如何告诉 git 在子树合并期间忽略某些文件夹和文件?
【发布时间】:2012-07-31 13:49:42
【问题描述】:

我的主分支具有以下目录结构

templates/something.lib
templates/libs/1.lib

我还有一个 templates_master 分支,其中包含以下文件(就在根目录中)

a.html
b.html

然后我去 master 并将模板加载到 master templates 文件夹中

git read-tree --prefix=templates/ -u templates_master

现在形成这个主结构

templates/something.lib
templates/libs/1.lib
templates/a.html
templates/b.html

然后我留在 master 并在 templates/a.html 中引入一些更改,并进行几次提交。现在我希望这个修改过的 templates/a.html 回到原来的分支。我切换到 templates_master 分支并运行此命令

git merge -s subtree master

然而,这个命令不仅将 master:templates/a.html 复制到 templates_master:a.html,而且还复制了那些 libs 文件,所以基本上现在我的 templates_master 分支拥有原始 master templates/ 所拥有的一切。是否可以告诉 git 仅将某些文件和文件夹保留在 master 分支中,或者此逻辑是否在 git 级别上硬编码,即在子目录合并期间,它使用指向 templates/ 的树状结构,并且 templates/ 中的所有内容都是并且只能是子目录模板/?

【问题讨论】:

  • 是的,很遗憾,cherry-pick 不是一个解决方案。我正在尝试构建一个自动化系统,它将进行主模板更改,将这些更改移动到单独的“主模板”分支,然后主模板将合并到主题分支中:templates_theme1、templates_theme2 等。问题是产品的方式是结构化的——templates/ 文件夹下的一些东西与模板无关,也不需要进入那些最终的 templates_theme1 分支。

标签: git git-merge git-subtree


【解决方案1】:

不幸的是,我很确定这是子树工作流程的要求。它们毕竟被称为“子树”。子树的任何路径中都不能有超级项目文件。

这就是说,这出现了很多!我想知道是否有人会想到一个解决方案。

想象一下,如果您可以将 2 个项目合并到同一个文件夹中?您将如何处理 README 等常见文件?如果您添加一个新文件,您会期待什么? git 怎么知道你将它添加到哪个项目? perforce 中几乎需要一个类似于 clientspec 映射的新概念来满足这种需求。

现在尝试将您的子项目保存在子文件夹中。

【讨论】:

    猜你喜欢
    • 2019-12-12
    • 2013-02-20
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 2010-11-19
    • 2013-10-13
    • 1970-01-01
    相关资源
    最近更新 更多