仅在一个文件上应用git merge stategy? [英] Apply git merge stategy only on one file?

查看:46
本文介绍了仅在一个文件上应用git merge stategy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将一个分支合并到另一个分支时,可以像这样定义合并策略

When merging a branch into another, it is possible to define the merge strategy like

git merge release -X ours

在将发布分支中的内容合并到当前分支中时,这将全局应用策略我们的".是否可以仅在一个特定文件上应用此策略,例如

This applies the strategy "ours" globally when merging stuff from the release branch into the current branch. Is it possible to apply this strategy only on one specific file like

git merge release -X docs/release-notes.md ours 

以便仅在合并docs/release-notes.md文件时使用我们的"策略?还是有人意识到实现这一目标的另一种选择?

so that the "ours" strategy is only used when merging docs/release-notes.md file? Or is anybody aware of another option to achieve that?

推荐答案

git合并对跟踪内容的不同状态起作用,而不对单个文件起作用.改而言,git看不到涉及两个文件的提交或涉及涉及一个文件的提交的根本区别.

git merges operate on different states of the tracked content, not on individual files. Rephrasing, git does not see any fundamental difference between a commit touching two files or a commit touching one file.

因此,在干净的git工作流程中,人们期望提交和分支策略之间存在主题上的一致性.更具体地说,产生修复主题"的提交比修复特定文件的提交更麻烦".拥有包含针对特定主题"所做的工作的分支而不是解决特定文件开发问题的分支,这更加令人讨厌".

There is therefore an expectation in a clean git workflow that there is a thematic coherence in commits and branching strategies. More specifically, it's more "gitty" to produce a commit that fixes a "subject" than a commit that fixes a specific file. It's more "gitty" to have branches that contain work done towards specific "topics" rather than branches addressing the development of specific files.

将其与您的问题相关联,而又不了解您的代码库或git策略,有可能需要根据单个文件的状态不同地合并特定分支,这表明分支模型可能需要一些改进

Relating this back to your question, without knowing too much about your codebase or git strategy, it's possible that the need to merge a specific branch differently according to the state of individual files indicates that the branching model might need a bit of polishing.

如果您希望在release分支中进行更改,而不希望在release分支中对README.md文件进行更改,则可能需要以某种方式拆分从release开始的README.md中的更改,以便您可以合并释放分支而不合并对README.md的更改.但是,考虑到该分支称为发布,我想您根本不想在这个分支上加分.

If you want the changes in the release branch but not the changes in the README.md file in the release branch then it's possible that the changes in README.md from release might need to be split out somehow so you can merge the release branch without merging changes to README.md. However given that the branch is called release I imagine you don't want to bang on it very hard at all.

如果需要从发行版合并但又忽略README.md更改,那么可以考虑设置一个并行分支来发行,例如release-noreadme.然后,您可以随意打开所有未发布版本,包括按摩README.md文件以适合您的需要,这样您就可以从未发布版本合并,而不必担心脚尖地关注特定文件中的特定更改.

If your need to merge from release but ignore README.md changes is recurrent, you might consider setting up a parallel branch to release like release-noreadme. Then you can bang on release-noreadme all you want, including massaging the README.md file to suit your needs, such that you can then merge from release-noreadme without worrying about tiptoeing around specific changes in specific files.

tl; dr:考虑同步一个分支以发布,您可以在其中消除不需要的更改,然后从该分支合并而不是发布.

这篇关于仅在一个文件上应用git merge stategy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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