合并分支时忽略文件 [英] Ignore files when merging branches

查看:691
本文介绍了合并分支时忽略文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我合并分支时,我想忽略每个分支之间的 web.config ,因为每个分支在web.config中都有不同的配置。

某些原因,它不起作用。

我缺少什么?


这是我迄今为止。

.gitattributes



  * text = auto 
网页.config merge = our



文件结构



  .gitignore 
.gitattributes
项目
| ____目录
| ____目录2
| _____ Web.config

我也将merge.ours.driver设置为true:

  git config --global merge.ours.driver true 


解决方案


今天我添加了一些新文件并更改了一些文件,但是当我在本地合并时,这不起作用。


A

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

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


When I merge branches I am trying to ignore web.config between each branch because each branch have different configuration in web.config.

Some reason, it is not working.
Am I missing something?

This is what i have so far.

.gitattributes

* text=auto
Web.config merge=ours

File Structure

 .gitignore
 .gitattributes
 project
 |____directory
 |____directory2
      |_____Web.config

I also set merge.ours.driver to true:

git config --global merge.ours.driver true

解决方案

today I added a few new files and change some files but when i merge locally, this is not working.

A merge strategy like merge=ours only applies on specific files when they have conflicts. If you change a file only in one branch, then merge that branch, there is no conflict (ie, no concurrent modification).

In other words, merge=ours is not the right solution for your case (whether or not you are using Visual Studio 2015).

I would rather:

  • have a separate file per branch (web.config.master, web.config.mybranch, ...), in which you can modify each file as you want
  • declare a content filter driver (using a .gitattributes declaration) which would, on checkout automatically copy the right file as web.config.
    That web.config copied file would remain ignored and private.

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

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

这篇关于合并分支时忽略文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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