如何在Git中实现部署分支 [英] How to realise a deployment branch in Git
问题描述
我创建了一个分支,用于部署。它有一些差异,如不同的配置文件和文档。
我不能忽视他们,因为那么他们会留在两个分支,而我想保持它们在两个分支中都不同。
问题是,当我合并分支时,那些意图不同的文件也被合并。
有没有办法完成这样的事情?
我不知道Git是用这种方式使用的。
首先快速 Linus建议,总是多彩和信息丰富;)
Git 非常从根本上跟踪项目状态,而不是文件州。这意味着你非常无法尝试合并文件。在git中这是一个无谓的操作,事实上,任何允许它的SCM注定是一个完整的sh t()。
(p)(*)我不是说git不这样做。这比这更重要。一旦您开始执行每个文件的分支和合并,您基本上已经搞砸了自己,您将永远无法将该项目作为整个项目工作 - 您不再具有明确的历史记录,实际上是整个项目的历史。
有。
可以这样说:你可以:
- 管理这些config / doc文件一个单独的git子项目注意:使用子模块已在此讨论)
- 或记录部分合并(对我们不想合并的文件使用我们的策略),然后修改它。
此线程中的其他解决方案涉及在部署服务器上执行服务器特定分支。
开发部署
#origin / master:
x - x $ git clone
#ma ster
x - x
$ git checkout -b部署原始/主
x - x
\
- #deployment
$ ....#配置文件的更改
#or其他特定部署文件
x - x
\
--d1 - d2#无需推动该分支。
#new developments
x - x - x - x
$ git pull --rebase #pull origin / master和
#在它的顶部重播当前分支
x - x - x - x
\
--d1' - d2'#SHA1在部署分支中重写
#不重要,因为这个分支
#is不推(已发布)
I'm using git for a PHP project, I think it's really handy. There is one thing that would be great if I get it to work.
I have created a branch, meant for deployment. It has some differences, like different configuration files and documentation.
I can't just ignore them, because then they will stay in both branches, while I would like to keep them different in both branches.
The problem is that when I merge the branches, those files that are meant to be different are merged too.
Is there any convenient way to accomplish such a thing? How is this normally done?
I am not sure Git is meant to be used this way.
First a quick Linus advice, always "colorful" and informative ;)
Git very fundamentally tracks project state, not file state. Which means that you very much can NOT try to "merge a file". It is a senseless operation in git, and in fact, any SCM that allows it pretty much is doomed to be a total piece of sht ().
(*) And I'm not saying that just because git doesn't do it. It's much more fundamental than that. Once you start doing per-file branching and merging, you've basically screwed yourself, and you'll never be able to work on the project as a "whole project" any more - you no longer have a well-defined history that actually is the history of the whole project.
There.
That said, you could:
- manage those config/doc files a separate git sub-projects (note: the use of submodules has been discussed here)
- or record partial merge (using "ours" strategy for files we don't want to merge), then --amend it.
Other solutions in this thread involve working on a "server-specific" branch on your deployment server
Development Deployment
#origin/master:
x--x $ git clone
# master
x--x
$ git checkout -b deployment origin/master
x--x
\
-- #deployment
$ .... #makes changes for config files
#or other specific deployment files
x--x
\
--d1--d2 # no need to push that branch ever.
#new developments
x--x--x--x
$ git pull --rebase #pull origin/master and
#replay current branch on top of it
x--x--x--x
\
--d1'--d2' #SHA1 rewritten in deployment branch
#not important since this branch
#is not pushed (published)
这篇关于如何在Git中实现部署分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!