代码之家  ›  专栏  ›  技术社区  ›  Yves

为什么git会给我冲突

  •  0
  • Yves  · 技术社区  · 6 年前

    说我有一个空的git存储库。以下是我执行的命令:

    echo 'aaa' > file
    git add .
    git commit -m 'a'
    echo 'bbb' >> file
    git commit -am 'b'
    echo 'ccc' >> file
    git commit -am 'c'
    

    然后我执行 git reflog 要获取日志:

    d3f79b4 HEAD@{0}: commit: c
    4c79a7f HEAD@{1}: commit: b
    a31df0d HEAD@{2}: commit (initial): a
    

    现在我想回到 commit: b ,意思是我想改变 file

    aaa
    bbb
    ccc
    

    aaa
    bbb
    

    我尝试执行命令: git revert 4c79a7f 但我得到了一些关于冲突的错误信息:

    error: could not revert 4c79a7f... b
    hint: after resolving the conflicts, mark the corrected paths
    hint: with 'git add <paths>' or 'git rm <paths>'
    hint: and commit the result with 'git commit'
    

    文件

    aaa
    <<<<<<< HEAD
    bbb
    ccc
    =======
    >>>>>>> parent of 4c79a7f... b
    

    此外,如果每次提交时创建三个文件,如下所示:

    touch file1
    git add .
    git commit -m 'a'
    touch file2
    git commit -am 'b'
    touch file3
    git commit -am 'c'
    

    我可以恢复到任何历史的承诺。

    git reset 但我想学习 git revert

    2 回复  |  直到 6 年前
        1
  •  1
  •   Philippe    6 年前

    当git尝试 revert

    您的“问题”是由于diff格式以及如何应用修补程序造成的。

    diff --git a/GitUI/UserControls/RevisionGrid/RevisionGridToolTipProvider.cs b/GitUI/UserControls/RevisionGrid/RevisionGridToolTipProvider.cs
    index 985995f39..91af87f84 100644
    --- a/GitUI/UserControls/RevisionGrid/RevisionGridToolTipProvider.cs
    +++ b/GitUI/UserControls/RevisionGrid/RevisionGridToolTipProvider.cs
    @@ -23,7 +23,6 @@ public void OnCellMouseEnter()
                 _toolTip.AutoPopDelay = 32767;
             }
    
    -        private int _oldIndex = -1;
             public void OnCellMouseMove(DataGridViewCellMouseEventArgs e)
             {
                 var revision = _gridView.GetRevision(e.RowIndex);
    @@ -36,9 +35,8 @@ public void OnCellMouseMove(DataGridViewCellMouseEventArgs e)
                 var oldText = _toolTip.GetToolTip(_gridView);
                 var newText = GetToolTipText();
    
    -            if (newText != oldText || _oldIndex != e.RowIndex)
    +            if (newText != oldText)
                 {
    -                _oldIndex = e.RowIndex;
                     _toolTip.SetToolTip(_gridView, newText);
                 }
    

    您可以看到代码添加(+)和删除(-)。

    如果应用修补程序的文件中的上下文行之一已更改,则修补程序不会自动应用,并且存在合并冲突。

    在修改的行上没有冲突,但是在上下文行上。。。

        2
  •  0
  •   choroba    6 年前

    git revert 4c79a7f ,您正在尝试还原(即“撤消”)提交 b ,而不是回到它。但git不知道如何做到这一点:它不知道是否应该保留 ccc

    推荐文章