简体   繁体   English

在构建时用新版本替换git子模块中的特定文件

[英]Replacing a specific file in git submodule with a new version at build time

I am using an open source repo as a git submodule inside my own project. 我在自己的项目中使用开放源代码回购作为git子模块。

Every time I build the whole project, I have to replace a specific file in the submodule with my own implementation. 每次构建整个项目时,都必须用自己的实现替换子模块中的特定文件。 How can I do that without forking the open source repo? 我如何做到这一点而无需派生开源仓库? (The open source project is under heavy development and I get lots of conflicts when I add my own logic) (开源项目正在繁重的开发中,当添加自己的逻辑时,我会遇到很多冲突)

Thanks! 谢谢!

没有足够的信息可以提供具体的建议,但是我想看看是否有办法通过扩展/覆盖基础仓库中的文件而不是替换文件来找到解决方案,正如我所能做到的那样。看不到任何地方领先。

Git doesn't offer a way to let you do this natively. Git没有提供让您本地执行此操作的方法。 The version of a submodule for a particular revision is fixed, and there isn't a way to replace files in the submodule the way that you want to without maintaining your own fork. 特定修订版本的子模块的版本是固定的,无法在不维护自己的fork的情况下以所需的方式替换子模块中的文件。

However, you can easily do this by changing how your build operates. 但是,您可以通过更改构建的运行方式轻松地做到这一点。 As part of your build process, you can copy all of the source files from one directory to another and replace or patch the files at that point, and then perform your build using the second directory as your source files. 作为构建过程的一部分,您可以将所有源文件从一个目录复制到另一个目录,然后替换或修补文件,然后使用第二个目录作为源文件执行构建。

Your question could use a little more info. 您的问题可能会使用更多信息。 There are multiple ways to solve your problem if i understand it correctly - 如果我正确理解,有多种方法可以解决您的问题-

  1. use a build script that overwrites the file in submodule and then invoke the actual toolchain to build. 使用可覆盖子模块中文件的构建脚本,然后调用实际的工具链进行构建。

  2. Take a look at git post clone hooks. 看看git post clone hooks。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM