【问题标题】:Is git-merge output correct?git-merge 输出是否正确?
【发布时间】:2020-08-27 19:34:04
【问题描述】:

我正在尝试分析 Github (https://github.com/antlr/antlr4) 的 ANTLR4 存储库中的合并历史。但是,当我尝试重放合并 fe1d61d9dba9f202982da85606cbb7493ce7bae8 时,有一个输出对我来说没有意义。所以我想知道是否有人可以帮助我。

合并 fe1d61d9dba9f202982da85606cbb7493ce7bae8 有两个父节点:103dc662c 和 31d21ff4d。因此,要重放合并,我执行以下步骤:

  1. git 结帐 103dc662c;和
  2. git 合并 31d21ff4d.

在这种情况下,存在一些冲突的文件。但是,文件“存储库路径”/runtime/Go/src/antlr/ErrorStrategy.go 显示以下冲突:

// @param recognizer the parser instance
// @param e the recognition exception
//
<<<<<<< HEAD:runtime/Go/src/antlr/ErrorStrategy.go
func (d *DefaultErrorStrategy) ReportInputMisMatch(recognizer Parser, e *InputMisMatchException) {
        var msg = "mismatched input " + d.GetTokenErrorDisplay(e.offendingToken) +
=======
func (this *DefaultErrorStrategy) ReportInputMisMatch(recognizer Parser, e *InputMisMatchException) {
        var msg = "mismatched input " + this.GetTokenErrorDisplay(e.offendingToken) +
>>>>>>> 31d21ff:runtime/Go/src/antlr4/ErrorStrategy.go
                " expecting " + e.getExpectedTokens().StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false)
        recognizer.NotifyErrorListeners(msg, e.offendingToken, e)
} 

当我尝试打开父版本中的原始文件时,左侧版本中的文件 (103dc662c) 存在,但正确版本的文件 (31d21ff4d) 不存在 >>>>>>> 31d21ff:runtime/Go/src/antlr4/ErrorStrategy.go。经过调查,我发现正确版本的文件也在路径 runtime/Go/src/antlr/ErrorStrategy.go 中。

我是不是误解了什么?

提前致谢, 格莱夫

【问题讨论】:

    标签: git merge path output git-merge


    【解决方案1】:

    让我们重复设置:

    $ git clone https://github.com/antlr/antlr4
    Cloning into 'antlr4'...
    remote: Enumerating objects: 2, done.
    remote: Counting objects: 100% (2/2), done.
    remote: Compressing objects: 100% (2/2), done.
    ^Rceiving objects:  21% (24258/115511), 16.64 MiB | 3.15 MiB/s    /s   
    remote: Total 115511 (delta 0), reused 0 (delta 0), pack-reused 115509
    Receiving objects: 100% (115511/115511), 61.89 MiB | 3.13 MiB/s, done.
    Resolving deltas: 100% (67916/67916), done.
    $ git checkout -b tmp 103dc662c
    

    到目前为止一切正常。现在我们将得到合并冲突以及许多我们应该注意的消息:

    $ git merge 31d21ff4d
    Auto-merging tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
    CONFLICT (content): Merge conflict in tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
    Auto-merging runtime/Go/src/antlr/Utils.go
    Auto-merging runtime/Go/src/antlr/Trees.go
    Auto-merging runtime/Go/src/antlr/Tree.go
    Auto-merging runtime/Go/src/antlr/Transition.go
    CONFLICT (rename/delete): runtime/Go/src/antlr4/TraceListener.go deleted in HEAD and renamed to runtime/Go/src/antlr/TraceListener.go in 31d21ff4d. Version 31d21ff4d of runtime/Go/src/antlr/TraceListener.go left in tree.
    Auto-merging runtime/Go/src/antlr/TokenStream.go
    Auto-merging runtime/Go/src/antlr/TokenSource.go
    Auto-merging runtime/Go/src/antlr/Token.go
    Auto-merging runtime/Go/src/antlr/SemanticContext.go
    Auto-merging runtime/Go/src/antlr/RuleContext.go
    Auto-merging runtime/Go/src/antlr/Recognizer.go
    Auto-merging runtime/Go/src/antlr/PredictionMode.go
    Auto-merging runtime/Go/src/antlr/PredictionContext.go
    Auto-merging runtime/Go/src/antlr/ParserRuleContext.go
    Auto-merging runtime/Go/src/antlr/ParserATNSimulator.go
    Auto-merging runtime/Go/src/antlr/Parser.go
    Auto-merging runtime/Go/src/antlr/LexerActionExecutor.go
    Auto-merging runtime/Go/src/antlr/LexerAction.go
    Auto-merging runtime/Go/src/antlr/LexerATNSimulator.go
    Auto-merging runtime/Go/src/antlr/Lexer.go
    Auto-merging runtime/Go/src/antlr/LL1Analyzer.go
    Auto-merging runtime/Go/src/antlr/IntervalSet.go
    Auto-merging runtime/Go/src/antlr/IntStream.go
    Auto-merging runtime/Go/src/antlr/InputStream.go
    Auto-merging runtime/Go/src/antlr/FileStream.go
    Auto-merging runtime/Go/src/antlr/Errors.go
    Auto-merging runtime/Go/src/antlr/ErrorStrategy.go
    CONFLICT (content): Merge conflict in runtime/Go/src/antlr/ErrorStrategy.go
    Auto-merging runtime/Go/src/antlr/ErrorListener.go
    Auto-merging runtime/Go/src/antlr/DiagnosticErrorListener.go
    Auto-merging runtime/Go/src/antlr/DFAState.go
    Auto-merging runtime/Go/src/antlr/DFASerializer.go
    Auto-merging runtime/Go/src/antlr/DFA.go
    Auto-merging runtime/Go/src/antlr/CommonTokenStream.go
    Auto-merging runtime/Go/src/antlr/CommonTokenFactory.go
    Auto-merging runtime/Go/src/antlr/CharStream.go
    Auto-merging runtime/Go/src/antlr/ATNType.go
    Auto-merging runtime/Go/src/antlr/ATNState.go
    Auto-merging runtime/Go/src/antlr/ATNSimulator.go
    Auto-merging runtime/Go/src/antlr/ATNDeserializer.go
    Auto-merging runtime/Go/src/antlr/ATNDeserializationOptions.go
    Auto-merging runtime/Go/src/antlr/ATNConfigSet.go
    Auto-merging runtime/Go/src/antlr/ATNConfig.go
    Auto-merging runtime/Go/src/antlr/ATN.go
    Removing pb/src/parser/T.g4
    Removing pb/src/parser/T.g
    Removing pb/src/parser/S.g4
    Removing pb/src/parser/M.g4
    Removing pb/src/parser/JSON.g4
    Removing pb/src/parser/Expr.g4
    Removing pb/src/parser/Arithmetic.g4
    Removing pb/src/parser/.gitignore
    Removing pb/src/input
    Removing pb/src/Test.go
    Removing antlr.go
    Automatic merge failed; fix conflicts and then commit the result.
    

    注意前面提到的重命名/删除冲突:

    CONFLICT (rename/delete): runtime/Go/src/antlr4/TraceListener.go deleted in HEAD
    and renamed to runtime/Go/src/antlr/TraceListener.go in 31d21ff4d. Version
    31d21ff4d of runtime/Go/src/antlr/TraceListener.go left in tree.
    

    (我添加的换行符)。

    当我尝试打开父版本中的原始文件时,左侧版本中的文件...存在,

    这很好,但是很明显至少一侧重命名了至少 一些 个文件,我们应该预料到这些文件在三个输入提交中可能具有不同的名称。

    ...正确版本的文件...在路径runtime/Go/src/antlr/ErrorStrategy.go中。

    我在runtime/Go/src/antlr/ErrorStrategy.goMERGE_HEAD aka 31d21ff4db8ddcf76bae1b865cd568621bfd5b4d 中找到了这个。

    然而,在 merge base 提交中:

    $ git merge-base --all HEAD MERGE_HEAD
    3406acabe51e89c57fc26aca02aeb7cbc30119bd
    

    仓库在runtime/Go/src/antlr4/ErrorStrategy.go:

    git ls-tree -r 3406acabe51e89c57fc26aca02aeb7cbc30119bd | grep ErrorStrategy.go
    100644 blob aed0ef94b5409f8035897496610446a5cbb52ef2    runtime/Go/src/antlr4/ErrorStrategy.go
    

    换句话说,这两个合并输入提交似乎都遵循了相同的重命名模式。从合并基础到 HEAD 的差异,以及从合并基础到 31d21ff4d 的差异,都将 antl4 子目录重命名为 antlr

    这一切都很正常。如果您正在执行手动合并解析,您可能会发现将merge.conflictStyle 设置为diff3 很有帮助。如果您希望让 Git 为您查找文件,请考虑使用 git mergetool 提取输入文件:它应该会自动为您查找合并基础、HEAD 和 MERGE_HEAD 文件。

    【讨论】:

      【解决方案2】:

      托雷克,

      非常感谢。但是,在 Git 合并文档(https://git-scm.com/docs/git-merge)中,有如下示例:

      Here are lines that are either unchanged from the common
      ancestor, or cleanly resolved because only one side changed.
      <<<<<<< yours:sample.txt
      Conflict resolution is hard;
      let's go shopping.
      =======
      Git makes conflict resolution easy.
      >>>>>>> theirs:sample.txt
      And here is another line that is cleanly resolved or unmodified.
      

      所以我希望是这样的:

      // @param recognizer the parser instance
      // @param e the recognition exception
      //
      <<<<<<< HEAD:runtime/Go/src/antlr/ErrorStrategy.go
      func (d *DefaultErrorStrategy) ReportInputMisMatch(recognizer Parser, e *InputMisMatchException) {
              var msg = "mismatched input " + d.GetTokenErrorDisplay(e.offendingToken) +
      =======
      func (this *DefaultErrorStrategy) ReportInputMisMatch(recognizer Parser, e *InputMisMatchException) {
              var msg = "mismatched input " + this.GetTokenErrorDisplay(e.offendingToken) +
      >>>>>>> 31d21ff:runtime/Go/src/antlr/ErrorStrategy.go
                      " expecting " + e.getExpectedTokens().StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false)
              recognizer.NotifyErrorListeners(msg, e.offendingToken, e)
      } 
      

      在这种情况下,两个分支都被重命名。但是,>>>>>>> 31d21ff:runtime/Go/src/antlr/ErrorStrategy.go 行是 >>>>>>> 31d21ff:runtime/Go/src/实例中的 antlr4/ErrorStrategy.go。你觉得有意义吗?

      谢谢, 格莱夫

      【讨论】:

        猜你喜欢
        • 2019-11-30
        • 2018-01-29
        • 1970-01-01
        • 2016-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-06
        • 2011-04-17
        相关资源
        最近更新 更多