Git与JSON文件冲突 [英] Git conflicts with JSON files

查看:217
本文介绍了Git与JSON文件冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的网站已使用一堆带有翻译的JSON文件(每种语言一个文件)进行了本地化.文件内容如下:

Our website is localized using a bunch of JSON files with translations (one file per language). The content of the files looks like this:

{
    "Password": "Passwort",
    "Tables": "Tische"
}

许多团队成员同时编辑这些JSON文件,添加新短语并编辑现有短语,即使人们更改了不同的行,我们也会遇到很多冲突.

Many team members edit these JSON files at the same time, adding new phrases and editing existing ones, and we get lots of conflicts even though people are changing different lines.

有没有一种可以避免合并冲突的方式来设置git?

Is there a way to set up git in such a way that would help avoid merge conflicts?

P.S. 我发现此脚本可帮助本地合并: https://gist.github.com/jphaas/ad7823b3469aac112a52.但是,我对一种解决方案感兴趣,该解决方案可以为团队中的每个人解决该问题(甚至包括通过GitHub的Web界面编辑JSON的人).

P.S. I've found this script to help merge locally: https://gist.github.com/jphaas/ad7823b3469aac112a52. However, I'm interested in a solution that would fix the problem for everyone in the team (even for persons who edit JSONs through GitHub's web-interface).

推荐答案

即使人们改变的方式不同,我们也会遇到很多冲突 线

we get lots of conflicts even though people are changing different lines

情况并非如此,只有在同一行被不同的人修改,提交并随后合并的情况下,您才会发生冲突.

This shouldn't be the case, you only get conflicts if same line is modified by different people, committed and then later merged.

哦,我实际上尝试了一下,遇到了一些奇怪的问题.

Oh, I actually tried this out and encountered some odd problems.

提交1(主):

{
    "a": "1",
    "b": "2",
    "c": "3",
    "d": "4",
    "e": "5",
    "f": "6",
    "g": "7"
}

提交2(tmp)

{
    "A": "1",
    "B": "2",
    "C": "3",
    "d": "4",
    "e": "5",
    "f": "6",
    "g": "7"
}

提交3(主):

{
    "a": "1",
    "b": "2",
    "c": "3",
    "d": "4",
    "E": "5",
    "F": "6",
    "G": "7"
}

git merge tmp:正确的结果

{
    "A": "1",
    "B": "2",
    "C": "3",
    "d": "4",
    "E": "5",
    "F": "6",
    "G": "7"
}

但是,如果还修改了行"d",我就会发生冲突,也许git无法建立diff边界.我为避免这种愚蠢的git行为而提出的愚蠢建议是在JSON文件中添加"padding"(丑陋,不是吗,但是没有更多冲突了):

However I get conflicts if also row "d" was modified, maybe git wasn't able to establish diff boundaries. My stupid suggestion to avoid this stupid git behavior is to add "padding" to the JSON file (ugly, isn't it? But no more conflicts):

{
    "a": "1",

    "b": "2",

    "c": "3",

    "d": "4",

    "e": "5",

    "f": "6",

    "g": "7"
}

这篇关于Git与JSON文件冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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