Git ветка для экземпляров сайта?

488
diegueus9

Я работаю на нескольких сайтах, оба сайта нуждаются в почти одинаковом коде, за исключением некоторых изменений в изображениях и CSS или настройках.

Я только что закончил читать главу веток книги Pro Git и немного запутался, если ветка не лучшее решение для этой проблемы, разве это развилка?

Я имею в виду, что у нас есть экземпляры кода A и B, между A и B, различия в том, что такие вещи, как цвета CSS, URL-адреса, ключи API, но большая часть кода одинакова, так как я могу с этим справиться, мне нужно что-то вроде кода в A, а затем «исправить» это, чтобы получить B, но я не уверен, как сделать слияние, которое не переопределяет изображения ...

В любом случае, если это ветвь или ветвь, как я могу объединить новые функции в A без потери изменений в B?

7

2 ответа на вопрос

2
Seth Robertson

Why not create a "template" branch which has the stuff in common and merge that into the per-website branches? None of the customized stuff should ever appear in the template branch, and ideally the customized stuff would be isolated to special files, though that is not a strict necessity. If you can isolate to the file level, .gitignore the customized files on the template branch for safety.

When you make a change, change it on template and merge to each branch in turn. Each website should get the change applied to template and keep their customized work.

1
Kromey

That's a bit tricky, and I'm afraid there's no single "right" answer. I do agree that maintaining separate branches for A and B is not appropriate use of git.

Your first option is to simply fork one from the other. The downside, of course, is that you now have to maintain two separate code bases. Ugly.

The second option is to fork only the differences (e.g. the images and css directories). This would leave you with 3 git repositories: the code (only one code base to maintain, hooray!), the images/css/etc. for A, and the same for B. The downside with this approach is that it complicates deployment, especially if you have to deploy both code and style changes simultaneously.

Alternatively, you could certainly abuse git to maintain a single repository with both A and B as separate branches. No, it's not ideal, but strictly speaking it would work. However, it's arguably a messier solution to the problem than the first suggestion (forking A and B entirely).

No one but you (and your team) can tell you which is the "right" approach for your situation. I wish you the best of luck, though!

Похожие вопросы