我一直在使用Windows上的Git (msysgit)来跟踪我一直在做的一些设计工作的更改。

今天我一直在一台不同的PC上工作(与远程repo brian),我现在正试图将今天完成的编辑合并到我笔记本电脑上的常规本地版本。

在我的笔记本电脑上,我已经使用git pull brian master将更改拉到我的本地版本。除了主InDesign文档之外,一切都很好-这显示为冲突。

PC (brian)上的版本是我想保留的最新版本,但我不知道什么命令告诉回购使用这一个。

我试图直接复制文件到我的笔记本电脑上,但这似乎打破了整个合并过程。

有人能告诉我正确的方向吗?


当前回答

我的案子看起来像个bug....使用git 2.21.0

我拉了一下…它抱怨二进制文件:

warning: Cannot merge binary files: <path>
Auto-merging <path>
CONFLICT (content): Merge conflict in <path>
Automatic merge failed; fix conflicts and then commit the result.

然后这里的任何答案都没有产生任何有意义的输出。

如果我看一下我现在拥有的文件……这是我编辑的。如果我这样做:

git checkout --theirs -- <path>
git checkout --ours -- <path>

我得到输出:

Updated 0 paths from the index

我还保存着我那份文件如果我rm,然后签出,它会说1,但它仍然给我我的文件版本。

Git mergetool说

No files need merging

git状态显示

    All conflicts fixed but you are still merging.
    (use "git commit" to conclude merge)

一种选择是撤销提交…但我很不幸,我犯了很多错误,这是第一次犯错误。我不想浪费时间重复了。

为了解决这个疯狂的问题:

我只是跑了

git commit

这会丢失远程版本,并可能浪费一些空间存储额外的二进制文件…然后

git checkout <commit where the remote version exists> <path>

这样就能把远程版本还给我了

然后再次编辑文件…然后提交和推,这可能意味着用另一个二进制文件的副本浪费空间。

其他回答

mipadi的回答对我不太管用,我需要这样做:

Git签出——我们的路径/to/file.bin

或者,保持被合并的版本:

Git签出——他们的路径/to/file.bin

then

选择add path/to/file

然后我可以再次使用"git合并工具"继续处理下一个冲突。

从git签出文档

git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>... --ours --theirs When checking out paths from the index, check out stage #2 (ours) or #3 (theirs) for unmerged paths. The index may contain unmerged entries because of a previous failed merge. By default, if you try to check out such an entry from the index, the checkout operation will fail and nothing will be checked out. Using -f will ignore these unmerged entries. The contents from a specific side of the merge can be checked out of the index by using --ours or --theirs. With -m, changes made to the working tree file can be discarded to re-create the original conflicted merge result.

如果二进制文件不仅仅是一个dll文件,或者可以像图像一样直接编辑的文件,或者一个混合文件(你不需要丢弃/选择一个文件或另一个文件),真正的合并应该是这样的:

我建议搜索一个diff工具,针对你的二进制文件,例如,有一些免费的图像文件

npm install -g imagediff IIRC from https://github.com/uber/image-diff 或python https://github.com/kaikuehne/mirror.git 外面还有其他人

然后比较它们。

如果没有用于比较文件的diff工具,那么如果您有bin文件的原始生成器(也就是说,存在用于它的编辑器……)就像blender 3d一样,你可以手动检查这些文件,也可以查看日志,并询问其他人你应该包括什么) 并使用https://git-scm.com/book/es/v2/Git-Tools-Advanced-Merging#_manual_remerge输出文件

$ git show :1:hello.blend > hello.common.blend
$ git show :2:hello.blend > hello.ours.blend
$ git show :3:hello.blend > hello.theirs.blend

对于这种情况,Git签出接受我们的或他们的选项。因此,如果你有一个合并冲突,你知道你只是想从你合并的分支文件,你可以这样做:

$ git checkout --theirs -- path/to/conflicted-file.txt

使用该版本的文件。同样,如果您知道您想要自己的版本(而不是被合并的版本),则可以使用

$ git checkout --ours -- path/to/conflicted-file.txt

我使用Git工作流的Excel - https://www.xltrail.com/blog/git-workflow-for-excel应用程序来解决我的二进制文件相关的合并问题。这个开源应用程序可以帮助我高效地解决问题,而不用花费太多时间,让我选择正确的文件版本而不会有任何困惑。