有没有办法让 Git 将文件标记为冲突?
可以提交包含冲突数据的文件。有没有办法再次将这些文件标记为冲突,以便运行 git mergetool 将生成必要的文件并运行合并工具?
It's possible to commit files that contains conflict data. Is there a way to mark these files as conflicted again, so that running git mergetool will generate the necessary files and run the merge tool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最优雅的解决方案是从一开始就防止这个问题:
git config --global mergetool.[工具].cmd [命令行调用]
git config --global mergetool.[tool].trustExitCode false
The most elegant solution would be to prevent this problem from the very beginning:
git config --global mergetool.[tool].cmd [command-line call]
git config --global mergetool.[tool].trustExitCode false
据我所知,
当文件中仍包含冲突标记时,您将无法提交。...这并不完全正确:OP提到你可以(我在这里复制他的过去的bin),但这对于合并工具来说还不够再次触发:
正如Charles Bailey评论,并在此SO 答案,查询 mergetool 是因为索引中有同一个文件的 3 个实例:
git add
(使用任何内容(包括冲突标记)将自动删除其中 2 个,确保mergetool
不会再次被调用。As far as I know,
you won't be able to commit while a file still contain conflict markers in it.... which is not exactly true:The OP mentions that you can (I copy here his pastbin), but that won't be enough for the mergetool to be trigger again:
As Charles Bailey comments, and illustrates in this SO answer, the mergetool is queried because there are 3 instances of the same file in the index:
git add
(with whatever content, including conflict markers) will automatically removes 2 of them, ensuring themergetool
won't be called again.请使用 git update-index --unresolve
自从 git 1.7 起,它使用索引中的解析撤消信息来恢复所有 3 个阶段(1:base、2:ours、3:theirs): https://github.com/git/git/commit/8aa38563b22c84b06ea1fff9638cc1f44fda726f
Please use
git update-index --unresolve
Since git 1.7 it uses resolve-undo info from the index to restore all 3 stages (1:base, 2:ours, 3:theirs): https://github.com/git/git/commit/8aa38563b22c84b06ea1fff9638cc1f44fda726f
如果索引已经处于冲突状态,只需使用
--conflict=merge
标志检查文件:如果索引是干净的,因为已[错误地]添加了未解析的文件,只需重置它检查之前:
这将允许您正常恢复冲突解决(例如,
git mergetool
)。注意:应 @fourpastmidnight 的要求,将对 @jakub-narębski 的答案的评论提升为自己的答案。 :)
If the index is already in a conflict state, simply check out the file with the
--conflict=merge
flag:If the index is clean because the unresolved file has been [erroneously] added, just reset it before checking it out:
This will allow you to resume conflict resolution normally (e.g.,
git mergetool
).NOTE: Promoting a comment to @jakub-narębski's answer into its own answer by request from @fourpastmidnight. :)
您可以使用 git checkout --conflict=merge -- file 获取带有冲突标记的文件内容,但如果您已使用 git add file 清理了索引(或者如果GUI 为你做了这件事)这是行不通的。
有 git update-index --unresolve ,但它很hacky,并且工作得不太可靠。我认为它恢复的状态对于 git-mergetool 来说是不够的。
您可能需要重做合并,或者使用 git update-index --cacheinfo 手动设置阶段版本... git-stash 可以帮助您保留正确解决的冲突。
You can get contents of file with conflict markers using
git checkout --conflict=merge -- file
, but if you have cleaned up index by usinggit add file
(or if GUI did that for you) it wouldn't work.There is
git update-index --unresolve
, but it is hacky, and does not work very reliably. I think the state it restores would be not enough for git-mergetool.You would probably have to redo merge, or use
git update-index --cacheinfo
to manually set stages version... git-stash can help you preserve correctly resolved conflicts.