Git - How do I manage built files in different branches?

后端 未结 5 606
滥情空心
滥情空心 2021-01-07 23:21

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.

相关标签:
5条回答
  • 2021-01-08 00:02

    Have you thought about worktrees?

    $ git worktree add ../branch2 branch2
    

    This will create a working tree checkout out to branch2

    $ cd ../branch2
    $ git branch
    * branch2
    

    You only have 1 local repo, but 2 different working areas, one for master and the other for branch2.

    That way you can keep the object files separate as well.

    0 讨论(0)
  • 2021-01-08 00:05

    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.

    0 讨论(0)
  • 2021-01-08 00:08

    The problem is that you need to get back the right binaries:

    • not only need for the right branch,
    • but also for the right version

    The last point is not overly important if you keep developing the latest versions of your 2 branches (and accept to rebuilt everything if you checkout an old tag and branch from there).
    But still, if after a build you automatically publish those '.o' files into a repository made for managing binaries, that would solve your problem neatly.
    A local Nexus repo for instance would be appropriate.

    0 讨论(0)
  • 2021-01-08 00:08

    I usually solve these kind of problems by creating 2 clones of the repo to 2 separate folders (called customer_a and customer_b) and checkout branch1 in one folder and branch2 in the other folder.

    0 讨论(0)
  • 2021-01-08 00:15

    Perhaps I'm missing something obvious, but when switching branches, Git won't touch untracked or ignored files, so if you build a product in one branch and then switch to another branch, the built products should remain.

    0 讨论(0)
提交回复
热议问题