git:我如何在分支之间进行合并,同时保持一个分支独占的某些变更集? [英] git: how do I merge between branches while keeping some changesets exclusive to one branch?

查看:958
本文介绍了git:我如何在分支之间进行合并,同时保持一个分支独占的某些变更集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在地狱中有一个特殊的地方,它将绝对路径和数据库证书硬编码到Web应用程序中的多个随机位置。可悲的是,在他们下地狱之前,他们正在对地球造成严重破坏。我们必须处理他们的代码。



我必须对其中一个Web应用程序执行一些小的更改。我创建了一个新的分支 features ,并执行全局查找&替换为更新我的本地环境的路径和凭据。我承诺。我也把这个标签标记为 local 。



我快速跳入危险的黑客忏悔之中,我想将我的特性更改合并到 master 分支中,但我不想要一个 local 提交合并。



此后,我将在 master 特性,并且我希望 local 保留在特性中,并且永远不会出现在 master 中。



理想情况下,我希望所有这些都是奇迹般地发生的,只要有一点有趣的参数和尽可能多的东西。



有没有一种简单的方法可以做到我失踪?



我可以考虑一对夫妻,但他们都要求我记住,我不希望提交。这绝对不是我的特长。特别是对于这样糟糕的黑客程序。



如果不这样做,我有兴趣使用更复杂的手动方法来处理这种情况。

解决方案

我对这个问题的解决方案使用了rebase而不是merge

从这样的提交树开始:

  abc < -  master 
\
d < - local
\\ \\
efg< - dev

$ git rebase --onto master local dev

  master 
V
abc -e'-f'-g'< - dev

d< - 本地

$ git checkout master



$ git merge dev

  master 
V
abc -e'-f'-g'< - dev
\
d< - 本地

$ git rebase --onto master master local

  master 
V
abc -e'-f'-g'< - dev
\
d'< - 本地

$ git branch -f dev local

  master 
V
abc -e'-f'-g'
\
d'< - 本地
^
dev


There's a special place in hell for people who hardcode absolute paths and database credentials into multiple random places in web applications. Sadly, before they go to hell they're wreaking havoc on Earth. And we have to deal with their code.

I have to perform a few small changes to one of such web applications. I create a new branch features, and perform a global find & replace to update the paths and credentials to my local environment. I commit that. I also tag this as local.

I merrily leap into perilous hacking penitence, and after a perplexing hundred patches, I want to merge my features changes into the master branch, but I do not want the one local commit to be merged.

Onwards, I'll be merging back and forth between master and features, and I'd like local to stay put in features, and never ever show up in master.

Ideally, I'd like all this to happen magically, with as little funny parameters and whatnot as possible.

Is there a simple obvious way to do it that I'm missing?

I can think of a couple, but they all require me to remember that I don't want that commit. And that's definitely not my forte. Especially with such poorly hacked programs.

Failing that, I'm interested in more convoluted, manual-ish ways to handle the situation.

解决方案

My solution to this problem uses rebase rather than merge

Starting with a commit tree like this:

a-b-c <-- master
 \
  d <-- local
   \
    e-f-g <-- dev

$ git rebase --onto master local dev

       master 
       V 
   a-b-c-e'-f'-g' <-- dev
     \
      d <-- local

$ git checkout master

$ git merge dev

               master 
               V 
   a-b-c-e'-f'-g' <-- dev
     \
      d <-- local

$ git rebase --onto master master local

               master 
               V 
   a-b-c-e'-f'-g' <-- dev
                \
                 d' <-- local

$ git branch -f dev local

               master 
               V 
   a-b-c-e'-f'-g'
                \
                 d' <-- local
                 ^
                 dev

这篇关于git:我如何在分支之间进行合并,同时保持一个分支独占的某些变更集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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