如果我解决冲突会不会改变Git责备? [英] If I Resolve a Conflict Does it Change Git Blame?

查看:122
本文介绍了如果我解决冲突会不会改变Git责备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚合并冲突是否对错误负责,但是我遇到了困难,因为我不清楚冲突解决如何影响 git blame

假设我在master中有一个文件:

 一(); 
b();
c();

我在master中修改它:

  A(); 
d();
c();

但是同事也是如此,他们对此进行了不同的修改,合并到master:

  a(); 
e();
c();

解决冲突会影响责任吗?换句话说,如果我的同事通过我的版本解决冲突:


d();
c();

和I git blame d(); line,谁会被指责:我还是我的同事?同样的,让我们说git弄糊涂了并认为第一行和第二行都有冲突:

 <<<< 
a();
d();
====
a();
e();
>>>>

如果我的同事解决了与他们版本的冲突:

  a(); 
e();
c();

和I git blame a(); 行,我(该行的原作者)会受到责备,还是会让我的同事(最后一次触摸它,即使它们没有改变它)得到责备?

解决方案

tl; dr



如果你在合并的文件上运行 git blame ,您将看到每行的原始作者,无论谁进行了合并提交。这意味着如果您的同事决定使用该行的您的版本解决冲突,那么您的姓名将显示在其旁边。



重建文件的历史记录



在Git中,每个提交包含两个关键信息:


  • 在提交时您的工作目录的快照的引用。

  • 引用它之前的提交它的


    鉴于这两个事实,Git可以通过从一个给定的提交中退回,在每个步骤中生成当前版本的文件和前一个版本之间的差异。



    这正是 git blame 的确如此。当你在一个文件上执行 git blame 时,Git会在的基础上重建文件的历史记录,向你显示作者提交引入(即添加)每行。



    合并提交



    A merge commit提供了两个父母的引用:


    • 您合并到的分支引用的提交,又名 left side。

    • 您分支引用的提交合并,也就是侧。 / li>


    快照包含每一方合并的所有更改。

    如果您在一个 merge commit 上做一个 git blame ,Git将走两行历史记录,每个父提交一行。一旦Git到达其快照添加某个行的提交,它会在该行旁边显示该提交的作者。



    解析时添加新行冲突



    如果添加了一行新行 - 即不属于合并任何一侧的行 - 作为一个冲突解决方案,该行将属于合并提交本身所引用的快照。在这种情况下, git blame 会报告该行的合并提交的作者。


    I'm trying to figure out whether a merge conflict was responsible for a bug, but I'm having difficulty because I'm not clear on how conflict resolution affects git blame.

    Let's say I have a file in master:

    a();
    b();
    c();
    

    I modify it in master:

    a();
    d();
    c();
    

    but so does a co-worker, and they modify it differently, in a separate branch which they then merge in to master:

    a();
    e();
    c();
    

    Can resolving that conflict affect the blame? In other words, if my co-worker resolves the conflict by going with my version:

    a();
    d();
    c();
    

    and I git blame the d(); line, who will be blamed: me or my co-worker?

    Similarly, let's say git got confused and thought both the first and second lines were conflicted:

    <<<<
    a();
    d();
    ====
    a();
    e();
    >>>>
    

    If my co-worker resolves the conflict with their version:

    a();
    e();
    c();
    

    and I git blame the a(); line, will I (the line's original author) get the blame, or will my co-worker (who "touched" it last, even though they didn't change it) get the blame?

    解决方案

    tl;dr

    If you run git blame on a merged file you are going to see the original author of each line, regardless of who did the merge commit. This means that if your co-worker decided to resolve the conflict using your version of the line, your name will be shown next to it.

    Reconstructing the history of a file

    In Git each commit holds two key pieces of information:

    • A reference to a snapshot of your working directory at the time of the commit.
    • A reference to the commit that came before it, aka its parent.

    Given these two facts Git can reconstruct the history of changes occurred in a file by walking backwards from a given commit, generating at each step a diff between the current version of the file and its previous one.

    This is exactly what git blame does. When you do git blame on a file, Git will reconstruct the history of the file on a line by line basis, showing you the author of the commit that introduced (i.e. added) each line.

    Merge commits

    A merge commit holds a reference to two parents:

    • The commit referenced by the branch you merged into, aka the left side.
    • The commit referenced by the branch you merged, aka the right side.

    The snapshot contains all the changes from each side combined.

    If you do a git blame on a merge commit, Git will walk two lines of history, one for each of the parent commits. Once Git reaches the commit whose snapshot added a certain line, it will show that commit's author next to the line.

    Adding new lines when resolving a conflict

    If a new line – that is a line that doesn't belong to either side of the merge – was added as part of a conflict resolution, that line would belong to the snapshot referenced by the merge commit itself. In that case git blame will report the author of the merge commit for that line.

    这篇关于如果我解决冲突会不会改变Git责备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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