如何在 Git 中实现部署分支 [英] How to realise a deployment branch in Git

查看:39
本文介绍了如何在 Git 中实现部署分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 PHP 项目中使用 git,我觉得它真的很方便.如果我让它工作,有一件事会很棒.

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?

推荐答案

2021 年 2 月更新:Git 本身仍然不合适,但 GitHub Action 环境可以提供帮助.

Update Feb. 2021: Git itself is still not a good fit, but GitHub Action environment could help.

2009:我不确定 Git 是否应该以这种方式使用.

2009: I am not sure Git is meant to be used this way.

首先快速Linus 建议,始终多彩"和信息;)

First a quick Linus advice, always "colorful" and informative ;)

Git 非常 从根本上跟踪项目状态,而不是文件状态.这意味着您不能尝试合并文件".在 git 中这是一个毫无意义的操作,事实上,任何几乎允许它的 SCM 都注定是一个彻头彻尾的 sh*t (*).

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 sh*t (*).

(*) 而且我并不是因为 git 不这样做而这么说.它比这更基本.一旦你开始对每个文件进行分支和合并,你基本上就搞砸了,你将永远无法将项目作为整个项目"进行工作.不再 - 你不再有一个明确定义的历史,它实际上是整个项目的历史.

(*) 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.

也就是说,您可以:

  • 在一个单独的 git 子项目中管理那些 config/doc 文件(注意:子模块的使用已经在这里讨论)
  • 或记录部分合并(对我们不想合并的文件使用我们的"策略),然后 --amend 它.

该线程中的其他解决方案涉及处理特定于服务器的"部署服务器上的分支

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屋!

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