我一直在使用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签出接受我们的或他们的选项。因此,如果你有一个合并冲突,你知道你只是想从你合并的分支文件,你可以这样做:

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

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

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

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

git commit -a

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

git checkout otherbranch theconflictedfile
git commit -a

详细解释

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

您还可以使用

git mergetool

这会导致git创建冲突二进制文件的本地副本,并在它们上生成默认编辑器:

{矛盾}。头 {矛盾} {矛盾}。远程

显然,在文本编辑器中无法有效地编辑二进制文件。相反,复制新的{conflicted}。远程文件{冲突}没有关闭编辑器。然后,当你关闭编辑器时,git会看到未修饰的工作副本已被更改,并且合并冲突已以通常的方式解决。