是否可以从父项目中修补Git中的子模块? [英] Is it possible to patch a submodule in Git from the parent project?
问题描述
我有一个项目 main
,其中包含一个子模块 foo
。对于这个特定的项目,我想对 foo
进行一个小的更改,该更改仅适用于这个特定的项目 main
。
main /
+ .git
+ main.c
+ lib /
| + bar.c
+ foo /#我的`foo`子模块
+ .git
+ config.h#我要从`main`
+修补的文件。 。
常见的解决方案是进入我的子模块,提交在名为
应用补丁程序,然后将其推送。不幸的是,这是一个非常糟糕的方法,因为我正在对 main-project
的新分支上为main foo
进行更改,而这仅对 main
重要。另外,当我将 foo
更新到最新版本时,我也必须挑选补丁,这会在 foo 中引入很多噪音
的历史。
另一种解决方案是在 main
上有一个真实的 patch 文件 foo
就在构建之前。不幸的是,由于这会修改子模块的内容,并且我将在 foo
上进行未提交的更改,因此它也不是一个好的解决方案。
理想的解决方案是使用Git跟踪我的补丁,但要在顶层(例如直接在 main
,而不是 foo
)。从理论上讲,可以在指向子模块位置的Git 树
上添加 blob
>
blob< sha> main.c
树< sha> lib /
commit< sha> foo
blob< sha> foo / config.h
有了这个主意,补丁文件 config.h属于
将在 foo
的 main
上进行跟踪。
怎么可能呢?
I仍然会使用第二个选项(在main上有一个真实的补丁文件),但是将构建过程调整为:
- 制作一个副本子模块中的
config.h
- 应用补丁
- build
- 将
config.h
恢复为其原始内容。
那样,我保持子模块状态不变。
OP在注释中添加:
但是您的解决方案无法在IDE中运行,Intellisense会感到困惑–
是的,我将通过涂抹/清除内容过滤器驱动程序在结帐时自动应用补丁,并在结帐时将其删除。
这样,该修补程序将在所有会话中都保留在原处,但在任何git status / diff / checkin上都将消失。 / p>
虽然这不是理想的方法,但似乎没有本机的Git处理方式。
I have a project main
that contains a submodule foo
. For this particular project, I would like to make a small change to foo
that only applies to this particular project main
.
main/
+ .git
+ main.c
+ lib/
| + bar.c
+ foo/ # My `foo` submodule
+ .git
+ config.h # The file I want to patch from `main`
+ ...
A common solution would be to go down to my submodule, make a commit Applied patch for main
on a new branch called main-project
, then push it. Unfortunately, this is a very bad approach because I am making changes to foo
that only matters to main
. Also, when I update foo
to the latest version, I will have to cherry-pick the patch too which introduces a lot of noise in foo
's history.
Another solution is to have a real patch file on main
that is applied to foo
just before the build. Unfortunately as this modifies the submodule content, and I will have uncommitted changed on foo
, so it is not a good solution either.
The ideal solution would be to track my patch using Git, but at the top-level (e.g. directly on main
, not on foo
). Theoretically, it would be possible to add a blob
on the Git tree
that points into the submodule location:
blob <sha> main.c
tree <sha> lib/
commit <sha> foo
blob <sha> foo/config.h
With this idea, the patched file config.h
belonging to foo
will be tracked on main
.
How is it possible to do it so?
I would still go with the second option (have a real patch file on main), but adapt my build process to:
- make a copy of the
config.h
in the submodule - apply the patch
- build
- restore
config.h
to its original content.
That way, I keep the submodule status unchanged.
The OP adds in the comments:
But your solution is not working in a IDE, Intellisense will be confused –
True: for that, I would apply automatically the patch on checkout, and remove it on checking, through a smudge/clean content filter driver.
That way, the patch remains in place during the all session, but would disappear on any git status/diff/checkin.
This is not ideal though, and there does not seem to be a native Git way to handle this.
这篇关于是否可以从父项目中修补Git中的子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!