GIT合并 - 维护一个分支的特定部分和其他所有部分 [英] GIT merge -keep specific parts of one branch and everything else of the other

查看:205
本文介绍了GIT合并 - 维护一个分支的特定部分和其他所有部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是场景



主分支


$ b - 文件名称:xxx-master.txt



- 文件内容:

代码
代码
ID = 01
代码
代码
代码



开发分支



<文件名>:文件名:xxx-dev.txt

- 文件内容:

代码
代码
ID = 02
代码
代码
代码



当把master放入dev时,我想保留xxx-dev.txt作为文件名和ID = 02,但是其他所有内容都来自master。反之亦然,将开发者合并到主人当中。这是我能让GIT理解的东西吗?

解决方案

这通常是您需要保留的情况(对于给定文件,这里 xxx-dev.txt 基于分支的不同内容,一种方法是:


  • 版本只有一个模板文件 xxx-dev.tpl

  • 分支: xxx-dev.dev xxx-dev.master :因为它们不同,所以没有合并问题。



为此,您可以注册(在
(图片来自 a href =http://git-scm.com/book/en / v2 / Customizing-Git-Git-Attributes#Keyword-Expansionrel =nofollow noreferrer>定制Git - Git Attributes ,来自 Pro Git book


$ b $ < smudge ( * - dev.txt )的脚本会自动生成(自动在 git checkout )实际 xxx-dev.txt 文件,方法是查看右边的 xxx-dev中的值。< branch> 值文件。
生成的实际 xxx-dev.txt 文件仍然被忽略(由 .gitignore )。



请参阅分支之间的git smudge / clean filter

a>。



您的 smudge 脚本可以通过以下方式确定签出分支的名称:


$ b $

  branch = $(git rev-parse --symbolic --abbrev-ref HEAD)


Here's the scenario

Master branch

-File name: xxx-master.txt

-File content:

code code ID=01 code code code

Dev branch

-File name: xxx-dev.txt

-File content:

code code ID=02 code code code

When merging master into dev, I'd like to keep xxx-dev.txt as the file name and ID=02, but everything else from master. And vice versa when merging dev into master. Is that something I can make GIT understand?

解决方案

This is typically a case where you need to keep (for a given file, here xxx-dev.txt) different content based on branches, one way is to:

  • version only a template file xxx-dev.tpl
  • version value files named after the branches: xxx-dev.dev, xxx-dev.master: since they are different, there is no merge issue.

For that, you would register (in a .gitattributes declaration) in your submodule repo a content filter driver.

(image from "Customizing Git - Git Attributes", from "Pro Git book")

The smudge script, associate to the template file (*-dev.txt), would generate (automatically on git checkout) the actual xxx-dev.txt file by looking values in the right xxx-dev.<branch> value file. The generated actual xxx-dev.txt file remains ignored (by the .gitignore).

See a complete example at "git smudge/clean filter between branches".

Your smudge script can determine the name of the checked out branch with:

branch=$(git rev-parse --symbolic --abbrev-ref HEAD)

这篇关于GIT合并 - 维护一个分支的特定部分和其他所有部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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