获取git不会合并二进制文件,但同时保留两个文件? [英] Get git to not merge binary files but keep both?

查看:47
本文介绍了获取git不会合并二进制文件,但同时保留两个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我们将二进制文件提交到源代码管理中,这些文件将由不同的人更改,然后重新提交.但是,这会产生合并冲突.

Currently we commit binary files into source control and these will be changed by different people and then re-committed. However this can produce merge-conflicts.

实际上,由于这些文件包含图像之类的东西,因此将它们合并是没有意义的.

Realistically as these files contain things like images it doesn't make sense to merge them.

我想知道是否有git命令允许二进制文件之间可能发生合并冲突.

I'm wondering if there is a git command that allows a possible merge conflict between binary files.

IE:有两个存储库和一个用于共享的裸露的远程存储库.有一个文件image.png,两个存储库的用户分别对其进行更改并提交.然后,他们拉出所做的更改,然后将其更改推到远程存储库中.显然,这会为其中一个用户生成合并冲突.但这对于图像文件没有意义,是否有可能最新的提交可以是最新的提交,而较旧的提交可以仅添加到分支的历史记录中?

IE: There is are two repositories and a bare remote repo which they use to share. There is a file image.png that the users the two repositories make seperate changes to and commit. They then pull the changes made and then push their changes to the remote repo. Obviously this generates a merge conflict for one of the users. But this doesn't make sense for image files, is it possible that the newest commit can be the most recent and the older commit can just be added to the history of the branch?

我很清楚这并不是应该做的事情,但这就是我所处的状况,所以我想知道是否有人可以解决问题.

I'm well aware this isn't exactly how things are supposed to be done, but this is the situation I'm in so I'm wondering if anyone has a solution.

推荐答案

是的. git reset 只是要替换的版本的冲突路径( git reset 与替换文件的提交 - paths ),提交,然后添加(或重置为)替换版本(即正确的版本)并提交结果.如果您不喜欢在主线上进行人为且已知不一致的提交,则还可以对被替换的文件进行 only 的孤立提交(带有一条提交消息,说明发生了什么事情)并将其作为提交的合并父项与主分支上的选定版本合并.在 git mktree git commit-tree 上阅读以了解如何做到这一点,这确实很容易.

Yep. git reset just the conflicting paths to the versions you want to supersede (git resetthecommitwiththesupersededfiles--paths), commit that, then add (or reset to) the replacement (i.e. correct) versions and commit the result. If you don't like having artificial and known-to-be-inconsistent commits on your mainline you could also make an orphan commit of only the superseded files (with a commit message saying what's up with them) and add that as a merge parent of the commit with the selected versions on your main branch. Read up on git mktree and git commit-tree to see how to do that, it's actually pretty darn easy.

这篇关于获取git不会合并二进制文件,但同时保留两个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆