避免使用git重新编译并制作 [英] Avoid recompilation with git and make
问题描述
我在git中有两个开发分支,而我经常需要在这两个分支之间进行更改.但是,真正令人沮丧的是,每次更改git中的分支时,整个项目都会重建,因为某些文件的文件系统时间戳会更改.
I have two development branches in git and I frequently need to change between the two. However, the really frustrating thing is that every time I change branches in git, the entire project gets rebuilt because the file-system timestamps for some files will change.
Ofc,配置了makefile以将项目构建到两个不同的构建目录中.
Ofc, the makefiles are configured to build the project into two different build directories .
有什么办法解决吗?编译是一个非常漫长且耗时的过程...
Is there any way around this? Compilation is a very long and time-consuming process...
-这是对该问题的较详细的说明... 说我有一个头文件Basic.h,它包含在许多其他文件中. Basic.h在分支1和分支2之间有所不同.
- This is a slightly more detailed explanation of the question... Say I have a header files Basic.h which is included in a number of other files. Basic.h is different between branch 1 and branch 2.
现在让我们说我已经将分支1编译为build_branch1,将分支2编译为build_branch2.假设我目前有2个分支机构已签出.现在,我签出分支1并更改File1.cpp并重新编译.理想情况下,由于自从我上次编译以来只有File1.cpp发生了更改,因此这是唯一应重新编译的文件.
Now let's say I have compiled branch 1 into build_branch1 and branch 2 into build_branch2. Say I have branch 2 currently checked out. Now I checkout branch 1 and change File1.cpp and recompile. Ideally, since only File1.cpp has changed since I compiled it the last time, this is the only file that should be recompiled.
但是,由于检出更改了Basic.h的时间戳,因此将重新编译包括Basic.h在内的所有文件.我想避免这种情况.
However, since Basic.h has it's timestamp changed due to the checkout, all files that are including Basic.h will get recompiled. I want to avoid this.
推荐答案
Git仅更改分支之间更新的文件.但是,即使更改了单个文件,如果编译器进行了完全重建,则始终可以克隆不同的分支并将其签出到不同的目录中.就像:
Git changes only the files that are updated between branches. But if your compiler does a full rebuild even if any single file was changed you can always clone and checkout your different branches into different directories. That's like:
/your-repo-name.branch1
/your-repo-name.branch2
这会占用额外的磁盘空间,但比在大型存储库中切换发散的分支要方便得多.
This takes extra disk space but is much more convenient than switching divergent branches in a huge repo.
这篇关于避免使用git重新编译并制作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!