首页 > 解决方案 > git 冲突可以像 svn 那样创建其他文件吗

问题描述

我在询问 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 进行比较。或者干脆选择一个文件,并将其设置为冲突的解决方案。

使用 git 并遇到冲突,我看到工作目录中的文件已满,带有 '>>>' '<<<' 标志。

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

任何想法?

标签: gitsvngit-merge-conflict

解决方案


如果您想查看冲突的基本版本(如果您问我,这是必须的),可以通过设置merge.conflictStylediff3. 我看到这个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的信息


推荐阅读