Git - 如何管理不同分支中的内置文件? [英] Git - How do I manage built files in different branches?

查看:181
本文介绍了Git - 如何管理不同分支中的内置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些背景



我现在一直在使用Git。我一直在从事的项目在分支/标签方面并没有太复杂。



我决定在工作中使用git-svn。 SVN存储库有许多不同的分支。很多这些分支都是客户定制版本的主干。

问题



我经常处理问题同时为不同的客户提供不同的服务。所以我总是在分支之间来回切换。问题在于,为了测试我每次在分支之间切换时重建项目的产品。构建需要大于2小时(从头开始):(b / b)

我假设有一种方法可以将分支中的构建文件存储在 customer_a ,然后签出 customer_b ,修改,构建,测试,提交然后隐藏构建文件并签出 customer_a 然后弹出 customer_a 存折以回到我所在的位置。



构建文件被跟踪(即添加或提交)。我不想跟踪构建文件,我绝对不希望检查它们。有没有办法为非跟踪文件存储(或做类似的事情)?或者人们用来实现相同类型的事情的常见做法是什么?

注意,我们的项目构建的每个库(其中有数千个)的构建方式获取文件本地的库文件夹,即它们不会移动到项目根目录下的生成文件夹。所有生成的文件都散布在整个地方。



更新。 ..



因此,基于一些评论,我认为我需要给出一个我的问题的例子



这是我的文件夹结构。 / p>

 分支1 / 
src /
分量1 /
c1.c
分量2 /
c2.c
libsrc /
library1 /
lib_1.c
library2 /
lib_2.c

branch2 /
src /
component1 /
c1.c
component2 /
c2.c
libsrc /
library1 /
lib_1.c
library2 /
lib_2.c

所以问题在于 branch1 branch2 具有相同的祖先,但分歧很大。因此,如果我检出 branch1 并构建它,我将得到我在 Makefile branch2 更改为<$ c $,则可以创建最终组件二进制文件。

c> c1.c 并运行make它尝试链接到由 branch1 (lib_1.o)创建的二进制文件,因为它们仍然存在在前一个分支建立的目录中。为了避免这种情况,我必须每次切换分支时执行一次干净的构建(这需要花费数小时)。

解决方案

好的



所以这个问题一直没有回答,我刚刚尝试了不同的解决方案。



最好的一个我



以下是我所做的


  1. 在存储库顶层创建一个 .binaries 文件夹并将其添加到 .gitignore

  2. 将二进制文件的文件格式添加到 .gitignore 文件中。用你最喜欢的脚本语言编写一个脚本来查找所有格式的文件,并将它们移动到 .binaries /< BRANCH> ; / 文件夹在相同的路径结构下,例如 src / library1 / lib1.o 应该被移至 .binaries /< BRANCH> /src/library1/lib1.o - 这应该通过预先结帐来调用

  3. 编写脚本以将文件从 .binaries 文件夹放入当前分支,例如 .binaries /< BRANCH> /src/library1/lib1.o 应该被移至 src / library1 / lib1.o - 这应该通过post-checkout调用


现在,在分支之间切换将恢复为构建的二进制文件只有在该分支期间,您将在创建新分支时进行干净的结帐。

Some Background

I have been using Git for a while now. The projects that I have been working on have not been too complicated in regards to branches/tags.

I have decided to use git-svn at work. The SVN repository has many different branches. A lot of these branches are customer customized versions of the trunk.

The Problem

I often work on problems for different customers at different the same time. So I switch back and forth between branches all the time. The problem is that to test the products I have to rebuild the project each time I switch between branches. A build takes > 2 hours (from scratch):(

I am assuming that there is a way to stash the build files in branch customer_a and then checkout customer_b, modify, build, test, commit. Then stash the build files and checkout customer_a again and pop the customer_a stash to get back to where I was.

This only works if the build files are tracked (i.e. added or committed). I do not want to track the build files and I definitely do not want to check them in. Is there a way to stash (or do something similar) for non-tracked files? Or a common practice that people use to achieve the same type of thing?

Note that the way our project gets built each library (of which there are thousands) gets builds the files local to the library folder i.e. they are not moved to a build folder at the root of the project. All the built files are spread out all over the place.

Update...

So based on some of the comments I think I need to give an example of my problem

Here is my folder structure.

branch1/
      src/
         component1/
                    c1.c
         component2/
                    c2.c
      libsrc/
          library1/
                    lib_1.c
          library2/
                    lib_2.c

branch2/
      src/
         component1/
                    c1.c
         component2/
                    c2.c
      libsrc/
          library1/
                    lib_1.c
          library2/
                    lib_2.c

So the problem is that branch1 and branch2 have the same ancestry but have diverged quite a bit. So if I check out branch1 and build it I will get binaries (e.g. lib_1.o) that I link against in my Makefile to build the final component binaries.

If I then checkout branch2 make a change to c1.c and run make it tries to link to the binaries that were created by branch1 (lib_1.o), since they still exist in the directories as built in the previous branch. To avoid this I have to do a clean build each time I switch branches (which takes hours).

解决方案

Okay

So this question has been unanswered for a while now and I just been trying different solutions locally.

The best one I came up with is to use pre amd post checkoout hooks.

Here is what I have done

  1. Create a .binaries folder at the top level of your repository and add it to the .gitignore file.

  2. Add the file formats of the binaries to your .gitignore file also.

  3. write a script in your favorite scripting language to find all files of said format that moves them to the .binaries/<BRANCH>/ folder under the same path structure e.g. src/library1/lib1.o should be MOVED to .binaries/<BRANCH>/src/library1/lib1.o - this should be called by pre-checkout

  4. Write a script to move files from the .binaries folder into the current branch e.g. .binaries/<BRANCH>/src/library1/lib1.o should be MOVED to src/library1/lib1.o - this should be called by post-checkout

Now switching between branches will revert to the binaries that were built during for that branch only and you will have a clean checkout when creating a new branch.

这篇关于Git - 如何管理不同分支中的内置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆