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

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

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

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

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

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


当前回答

从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.

其他回答

要解决这个问题,你需要将版本保存在当前分支中(忽略你正在合并的分支中的版本),只需添加并提交文件:

git commit -a

为了解决这个问题,你需要用你要合并的分支的版本来覆盖你当前分支中的版本,你需要首先检索那个版本到你的工作目录中,然后添加/提交它:

git checkout otherbranch theconflictedfile
git commit -a

详细解释

您必须手动解决冲突(复制文件),然后像这样提交文件(无论您是复制它还是使用本地版本)

git commit -a -m "Fix merge conflict in test.foo"

Git通常会在合并后自动提交,但当它检测到自己无法解决的冲突时,它会应用它找到的所有补丁,并将其余的补丁留给您手动解决和提交。Git合并手册页,Git- svn速成课程或这篇博客文章可能会对它的工作原理有所启发。

编辑:请看下面的帖子,你实际上不必自己复制文件,但可以使用

git checkout --ours -- path/to/file.txt
git checkout --theirs -- path/to/file.txt

以选择所需文件的版本。只有当你想混合使用两个版本时,才需要复制/编辑文件。

请将米帕迪斯的答案标记为正确答案。

我遇到过一个类似的问题(想要提交一个包含一些二进制文件的提交,这在合并时引起冲突),但遇到了一个不同的解决方案,完全可以使用git完成(即不必手动复制文件)。我想我应该把它包括在这里,这样至少我下次需要的时候可以记住它。:)步骤如下:

% git fetch

这将从远程存储库获取最新的提交(您可能需要指定一个远程分支名称,这取决于您的设置),但不会尝试合并它们。它在FETCH_HEAD中记录提交

% git checkout FETCH_HEAD stuff/to/update

这将获取我想要的二进制文件的副本,并使用从远程分支获取的版本覆盖工作树中的内容。Git不会尝试进行任何合并,因此您最终得到的只是来自远程分支的二进制文件的精确副本。完成之后,就可以像平常一样添加/提交新副本了。

如果二进制文件不仅仅是一个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

我遇到过在windows上使用Git管理二进制文件的差异/合并的两种策略。

Tortoise git lets you configure diff/merge tools for different file types based on their file extensions. See 2.35.4.3. Diff/Merge Advanced Settings http://tortoisegit.org/docs/tortoisegit/tgit-dug-settings.html. This strategy of course relys on suitable diff/merge tools being available. Using git attributes you can specify a tool/command to convert your binary file to text and then let your default diff/merge tool do it's thing. See http://git-scm.com/book/it/v2/Customizing-Git-Git-Attributes. The article even gives an example of using meta data to diff images.

我让这两种策略都适用于软件模型的二进制文件,但我们使用了tortoise git,因为配置很简单。