在 git pull --rebase
之后,我正处于 rebase 过程中。我有几个文件存在 merge 冲突。我如何接受“他们的”更改或“我的”对特定文件的更改?
$ 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
通常我只是打开文件或 merge 工具并手动接受所有“他们的”或“我的”更改。但是,我怀疑我缺少一个方便的 git 命令。
另外,请注意,只有当我看到哪些文件发生冲突以及可能的冲突是什么时,我才能为每个文件选择 merge 策略。
最佳答案
对于您获得的每个冲突文件,您可以指定
git checkout --ours -- <paths>
# or
git checkout --theirs -- <paths>
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 merge 策略 ("ours", "mine", "theirs"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16825849/