git合并策略适用于golang列样式。

huangapple go评论64阅读模式
英文:

git merge-strategy for golang column style

问题

有人知道如何为具有go-stylesheet的列格式的golang样式文件创建一个自定义的git合并策略吗?

情况

假设有一个像这样的结构体:

type Foo struct {
	Bar bool `json:bar`
}

现在有两个分支正在修改这个结构体:

分支A:

type Foo struct {
	Four bool `json:four`
	Bar  bool `json:bar`
}

分支B:

type Foo struct {
	Bar    bool   `json:bar`
	Sixsix string `json:six`
}

实际结果

当我尝试合并/变基这些分支时,显然会出现冲突,因为两个分支都修改了定义Foo.Bar的行。

期望结果

我正在寻找一种自定义的合并策略,可以自动合并冲突并生成格式良好的结构体。

type Foo struct {
	Four   bool   `json:four`
	Bar    bool   `json:bar`
	Sixsix string `json:six`
}
英文:

does anyone know a git custom merge strategy for golang styled files with the column-format of the go-stylesheet?

situation

Assume having a struct like this:

type Foo struct {
	Bar bool `json:bar`
}

now two branches are modifying this struct:

branch A:

type Foo struct {
	Four bool `json:four`
	Bar  bool `json:bar`
}

branch B:

type Foo struct {
	Bar    bool   `json:bar`
	Sixsix string `json:six`
}

actual result

When I now try to merge/rebase these branches, I get obviously a conflict because both branches modified the line defining Foo.Bar.

expected result

I am searching for a custom merge strategy which results in a well formatted struct with merging the conflict automatically.

type Foo struct {
	Four   bool   `json:four`
	Bar    bool   `json:bar`
	Sixsix string `json:six`
}

答案1

得分: 2

没有人能证明这是不可能的,但迄今为止也没有人找到方法,这在每个人的“如果能实现就好了”清单上都很高,很多人都努力尝试过。

触及相邻行通常意味着进一步的更改需要一些无法在不了解语义的情况下预测的修补。

为了说明为什么这很困难,考虑可以按两种顺序迭代的值,或者具有唯一主键的列表中的元素。

abc,1

这两个提示

abc,1
def,2

ghi,2
abc,1

应该合并为

ghi,3
abc,1
def,2

或者也许将2和3交换。或者其他什么。迄今为止,没有人找到Git可以知道这一点的方法,更不用说比手动修复更容易的方法了(一旦你有了一些经验,手动修复只需要两秒钟)。

英文:

Nobody can prove it's impossible, but nobody's found a way so far either, it's high on everybody's wouldn't-it-be-nice list and lots and lots of people have tried very hard.

Touching adjacent lines often means further changes need some touchup that can't be predicted without knowing the semantics.

For a demonstration of why it's hard, consider values that can be iterated in two orders, or elements in a list with a unique primary key.

abc,1

the two tips

abc,1
def,2

and

ghi,2
abc,1

should be merged as

ghi,3
abc,1
def,2

or maybe with that 2 and 3 swapped. Or whatever. Nobody's ever found a way Git could know this at all, let alone one that's easier than just fixing it manually (which takes like two seconds once you've got some practice).

huangapple
  • 本文由 发表于 2023年5月23日 08:44:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76310664.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定