git重置--合并vs git重置--保留

git重置--合并vs git重置--保留,git,git-reset,Git,Git Reset,我读过 , 然而,我很难理解两者之间的区别 git reset --merge 及 请提供一个简单的解释和/或示例。它们在处理合并冲突时是不同的,例如,这将产生冲突 git init echo 333>foo.txt git add foo.txt git提交-m 333 git签出-b特性 echo 444>foo.txt git提交-am 444 切换到主分支 echo 555>foo.txt git提交-am 555 git合并功能 然后 我同意文件不是很清楚。通过测试,我发现了三个不

我读过 , 然而,我很难理解两者之间的区别

git reset --merge


请提供一个简单的解释和/或示例。

它们在处理合并冲突时是不同的,例如,这将产生冲突

git init
echo 333>foo.txt
git add foo.txt
git提交-m 333
git签出-b特性
echo 444>foo.txt
git提交-am 444
切换到主分支
echo 555>foo.txt
git提交-am 555
git合并功能
然后


我同意文件不是很清楚。通过测试,我发现了三个不同之处,它们与文件发生的情况有关:

  • 有阶段性的变化
  • 没有未分期的更改
总之:

  • reset--merge
    始终丢弃索引(阶段性更改);如果任何文件上存在未分级和暂存的更改,则中止
  • reset--keep
    保留但取消保存索引;如果重置目标触及同一文件,则中止
测试场景:

echo First > file.txt
git add file.txt
git commit -m 'first'
git tag v1
echo Second >> file.txt
git commit -am 'second'
git tag v2
echo New > newfile.txt
git add newfile.txt
git commit -m 'third'
git tag v3
echo 'More stuff' >> file.txt
git add file.txt
我们现在有三个提交,并且'file.txt'在v1和v2之间发生更改,但在提交v2和v3之间没有更改

索引和新头之间没有变化 在这种情况下:

  • git reset——merge v2
    丢弃这些更改
  • git reset——keep v2
    保留它们,但不显示它们
指数和新头之间的变化 如果我们尝试重置为v1:

  • git reset--merge v1
    丢弃更改
  • git重置--保留v1
    拒绝:

    error: Entry 'file.txt' would be overwritten by merge. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
指数和新表头之间的变化,以及未分期的变化 现在,两者都失败了,但错误消息略有不同:

  • git重置--合并v1

    error: Entry 'file.txt' not uptodate. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
  • git重置--保持v1

    error: Entry 'file.txt' would be overwritten by merge. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
    error: Entry 'unrelated.txt' not uptodate. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
对不相关文件的暂存和未暂存更改 这有点奇怪:

  • git重置--合并v1

    error: Entry 'file.txt' would be overwritten by merge. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
    error: Entry 'unrelated.txt' not uptodate. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
  • git重置--保持v1

    error: Entry 'file.txt' would be overwritten by merge. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
    error: Entry 'unrelated.txt' not uptodate. Cannot merge.
    fatal: Could not reset index file to revision 'v1'.
    
    这两组更改都会保留,但不会老化

没有阶段性更改,但没有阶段性更改
为了完整起见,这两个文件的行为是相同的:重置成功,文件保持未老化。

IMHO它们不是完全重复的。这一个问它们是做什么的,另一个问你为什么要用它们。@SteveBennett我想,它们离我们很近,可以像傻瓜一样关上,但请随意投票重新打开。
error: Entry 'unrelated.txt' not uptodate. Cannot merge.
fatal: Could not reset index file to revision 'v1'.