gpt4 book ai didi

git - Git中如何实现一个部署分支

转载 作者:IT王子 更新时间:2023-10-29 01:19:14 25 4
gpt4 key购买 nike

我正在为一个 PHP 项目使用 git,我认为它非常方便。如果我让它发挥作用,那将是一件很棒的事情。

我已经创建了一个分支,用于部署。它有一些差异,例如不同的配置文件和文档。

我不能忽略它们,因为那样它们将留在两个分支中,而我想让它们在两个分支中保持不同。

问题是当我 merge 分支时,那些本应不同的文件也被 merge 了。

有什么方便的方法可以完成这样的事情吗?这通常是如何完成的?

最佳答案

2021 年 2 月更新:Git 本身仍然不太适合,但是 GitHub Action environment could help .

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

首先快速 Linus advice ,总是“丰富多彩”且信息丰富;)

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

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


那里。

也就是说,您可以:

  • 将这些配置/文档文件管理为单独的 git 子项目(注意:use of submodules has been discussed here)
  • 或记录部分 merge (对我们不想 merge 的文件使用“我们的”策略),然后 --amend 它。

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

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 - Git中如何实现一个部署分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/487753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com