git-merge输出正确吗?

问题描述

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

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

  1. git checkout 103dc662c;和
  2. git merge 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路径中。

我误解了吗?

预先感谢, Gleiph

解决方法

让我们重复设置:

$ 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.

(我添加了换行符)。

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

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

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

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

但是,在合并基础中提交:

$ 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提取输入文件:应该会自动为您找到merge-base文件,HEAD文件和MERGE_HEAD文件。

,

Torek

非常感谢。但是,在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 。对您有意义吗?

谢谢, Gleiph