git 冲突可以像 svn 那样创建额外的文件吗

can git conflict create additional files like svn does

我问的是 svn 特性,我想知道它是否存在 git:

当 svn 发生冲突时,它会创建一些有时有用的附加文件:

https://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-dug-conflicts.html

filename.mine - my original file as it existed at the working directory.

filename.BASE_REVISION - The file which is the BASE revision before you updated your working copy. It is the file checked out before you made your latest edits.

filename.NEW_REVISION - This is the file that Subversion client just received from the server. Actually this is the file we want to merge with.

这很有用,因为有时候,我想将我的本地更改与 base 进行比较,或者将远程更改与 base 进行比较。或者干脆 select 一个文件,并将其设置为冲突的解决方案。

使用 git 并发生冲突,我看到工作目录中的文件已满,带有“>>>”、“<<<”标志。

我可以从 git 获得与 svn 类似的行为,并拥有这些附加文件吗?我查看了 git 文档,但没有找到合适的内容。

有什么想法吗?

如果你想看到冲突的基础版本(这是必须的,如果你问我),可以通过将 merge.conflictStyle 设置为 diff3 来实现。我在 git help merge:

中看到了这个
4. For conflicting paths, the index file records up to three versions: stage 1 stores
   the version from the common ancestor, stage 2 from HEAD, and stage 3 from
   MERGE_HEAD (you can inspect the stages with git ls-files -u). The working tree
   files contain the result of the "merge" program; i.e. 3-way merge results
   with familiar conflict markers <<< === >>>.

所以,使用 git ls-files -u 你会得到文件列表,如果有冲突,你会得到类似的东西:

$ git ls-files -u
  100755 ac51efdc3df4f4fd328d1a02ad05331d8e2c9111 1 hello.rb
  100755 36c06c8752c78d2aff89571132f3bf7841a7b5c3 2 hello.rb
  100755 e85207e04dfdd5eb0a1e9febbc67fd837c44a1cd 3 hello.rb

那么你可以这样做:

git show :1:hello.rb # common ancestor
git show :2:hello.rb # HEAD
git show :3:hello.rb # the other branch

如果您想将它们作为文件进行分析,请使用重定向。

信息来自 https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging

最后我找到了一种更简单的方法来创建这些文件,尽管它并不简单。

git mergetool 命令生成所需的文件。如果我 运行 为给定的冲突文件使用不存在的合并工具的命令,它会生成类似于 svn 生成的基本文件、本地文件和远程文件:

git mergetool --tool whatever a.txt

给出输出:

Merging:
a.txt
Normal merge conflict for 'a.txt':
   {local}: modified file
   {remote}: modified file
Unknown merge tool whatever

现在 ls 显示已创建名为 'a_BASE'、'a_LOCAL'、'a_REMOTE'(进程 ID 添加到文件名)的新文件:

$ ls
a.txt  a_BACKUP_9348.txt  a_BASE_9348.txt  a_LOCAL_9348.txt  a_REMOTE_9348.txt