为特定文件(“我们的”,“我的”,“他们的”)选择Git合并策略 [英] Choose Git merge strategy for specific files ("ours", "mine", "theirs")

查看:124
本文介绍了为特定文件(“我们的”,“我的”,“他们的”)选择Git合并策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在 git pull --rebase 之后重新绑定的。我有几个合并冲突的文件。

  $ git status 
#不可以接受他们的更改或我的更改目前在任何分支上。
#您目前正在重组。
#(修复冲突,然后运行git rebase -continue)
#(使用git rebase --skip跳过这个补丁)
#(使用git rebase - abort检出原来的分支)

#要提交的更改:
#(使用git reset HEAD< file> ...以取消存储)

#修改:CorrectlyMergedFile

#未合并路径:
#(使用git reset HEAD< file> ...停用)
#(使用git add< file> ...来标记分辨率)

#两者都被修改:FileWhereIWantToAcceptTheirChanges
#都被修改:FileWhereIWantToAcceptMyChanges

通常我只是打开文件或合并工具并手动接受所有他们的或我的更改。但是,我怀疑我缺少一个方便的git命令。



另外,请注意,当我看到哪些文件时,我将只能为每个文件选择合并策略碰撞冲突可能是冲突的原因。

解决方案

对于每个冲突的文件,您可以指定

  git checkout --ours  - <路径> 
#或
git checkout - 他们 - <路径>

git checkout docs


git checkout [-f | --ours | --theirs | -m | --conflict =< style>] [< tree-ish>] [ - ]<路径> ... $ b

- 我们的

- 他们的

当从索引中检出路径时,请检查阶段#2( / code>)或#3(他们的)为未合并路径。
$ b 该索引可能包含未合并因为先前失败的合并而导致的条目。默认情况下,如果您试图从索引中检出这样的条目,则检出操作将失败并且不会检出任何内容。使用 -f 会忽略这些未合并的条目。通过使用 - 我们的 - 他们的可以检索合并的特定方面的内容>。使用 -m ,可以放弃对工作树文件所做的更改以重新创建原始冲突的合并结果。



I am in the middle of rebasing after a git pull --rebase. I have a few files that have merge conflicts. How can I accept "their" changes or "my" changes for specific files?

$ git status
# Not currently on any branch.
# You are currently rebasing.
#   (fix conflicts and then run "git rebase --continue")
#   (use "git rebase --skip" to skip this patch)
#   (use "git rebase --abort" to check out the original branch)
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:  CorrectlyMergedFile
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#       both modified: FileWhereIWantToAcceptTheirChanges
#       both modified: FileWhereIWantToAcceptMyChanges

Normally I just open the file or a merge tool and manually accept all "their" or "my" changes. However, I suspect I'm missing a convenient git command.

Also, note that I will only be able to choose a merge strategy for each file when I see what files hit conflicts an possibly what the conflicts are.

解决方案

For each conflicted file you get, you can specify

git checkout --ours -- <paths>
# or
git checkout --theirs -- <paths>

From the git checkout docs

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合并策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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