合并格式更改使用 git

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

Merge formatting changes using git

问题

我有一个MR请求。差异除了实际代码更改外,还显示了几个换行更改,这很可能是由于我的本地样式配置不同导致的。

            some_var = db.get_name(EMAIL).get('active', {}).get('email', "") << previous
            some_var = db.get_name(
                EMAIL).get('active', {}).get('email', "") << current

我尝试从主分支本地拉取最新内容,然后使用git merge将这些更改合并到我的分支。但显然,合并不会合并换行和空格更改。我甚至尝试禁用所有本地样式配置,但仍然没有成功。

有没有办法可以合并它们,这样我的MR只显示实际的代码更改,而不显示这些样式上的差异?

英文:

I have a MR request. The diff beside the actual code changes, also shows several line break changes, most probably due to difference in my local styling configurations.

        some_var = db.get_name(EMAIL).get(&#39;active&#39;, {}).get(&#39;email&#39;, &quot;&quot;) &lt;&lt; previuos
        some_var = db.get_name(
            EMAIL).get(&#39;active&#39;, {}).get(&#39;email&#39;, &quot;&quot;) &lt;&lt; current

I tried to locally pull latest from main branch and merge those changes to my branch using git merge. But apparently merge doesn't merge line breaks and white space changes. I even tried by disable all local styling configuration but still no success.

Is there a way I can merge those too, so my MR only shows actual code changes and not these styling differences?

答案1

得分: 2

> 但显然合并不会合并换行和空格的更改

不正确。

合并将自分支分歧点以来的两侧更改组合起来。如果自分歧点以来,一侧没有做任何更改,而另一侧有更改,那么有更改的一侧将获胜。因此,如果我们最初在分歧点处有以下代码:

some_var = db.get_name(EMAIL).get('active', {}).get('email', "")

并且一侧仍然保持着相同的代码:

some_var = db.get_name(EMAIL).get('active', {}).get('email', "")

但另一侧的最新更改如下:

some_var = db.get_name(
    EMAIL).get('active', {}).get('email', "")

然后将其中一个合并到另一个将导致以下结果:

some_var = db.get_name(
    EMAIL).get('active', {}).get('email', "")

因为这是发生了更改的部分。

> 所以我的MR只显示实际的代码更改,而不显示这些样式差异?

这是一个稍微不同的问题。让我们谈谈你的 "MR 显示"。

合并请求提议将一个分支合并到另一个分支。为了帮助审查请求,网站显示了与目标分支的 triple-dot diff。这不是在执行合并时将发生的描述;它是描述这个分支将为合并做出的贡献。

现在,你的合并请求建议将你的分支合并到 main 分支。因此,将 main 合并到你的分支应该对合并请求显示没有实际影响。main 的状态与 main 的状态没有区别;因此,从合并提交的结果来看,main 对你的分支的贡献不会出现在你的分支合并请求的显示中。

英文:

> But apparently merge doesn't merge line breaks and white space changes

Not true.

A merge combines the changes on both sides of the merge since the point where the branches diverged. If, since the point where the branches diverged, one side does nothing, and the other side does something, the something wins. So if we originally have, at the point where the branches diverged,

some_var = db.get_name(EMAIL).get(&#39;active&#39;, {}).get(&#39;email&#39;, &quot;&quot;)

and one branch still has

some_var = db.get_name(EMAIL).get(&#39;active&#39;, {}).get(&#39;email&#39;, &quot;&quot;)

but the latest from the other branch has

some_var = db.get_name(
    EMAIL).get(&#39;active&#39;, {}).get(&#39;email&#39;, &quot;&quot;)

Then merging one into the other will result in

some_var = db.get_name(
    EMAIL).get(&#39;active&#39;, {}).get(&#39;email&#39;, &quot;&quot;)

because that's what changed.

> so my MR only shows actual code changes and not these styling differences?

That's a slightly different matter. Let's talk about what your "MR shows".

A merge request proposes a merge of one branch into some other branch. To help with review of the request, the web site displays a triple-dot diff with the target branch. This is not a description of what will result when the merge is performed; it is a description of what changes this branch will contribute to the merge.

Now, your merge request proposes to merge your branch into main.
Merging main into your branch should therefore effectively have no effect on what the merge request displays. The state of main is, trivially, not a difference from the state of main; thus the contribution from main into your branch as a result of the merge commit does not appear in the display of your branch's merge request.

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

发表评论

匿名网友

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

确定