我正在调整基地在一次git拉之后,调整基地。我有一些文件合并冲突。我如何接受特定文件的“他们的”更改或“我的”更改?
$ 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
通常我只是打开文件或合并工具,手动接受所有“他们的”或“我的”更改。但是,我怀疑我错过了一个方便的git命令。
另外,请注意,只有当我看到哪些文件发生冲突或冲突可能是什么时,我才能为每个文件选择合并策略。
对于您获得的每个冲突文件,您可以指定
git checkout --ours -- <paths>
# or
git checkout --theirs -- <paths>
从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 rebase和merge的情况下,“他们的”和“我们的”意味着什么。请看这个链接
Git变基
他们的实际是目前的分支,在情况下的调整。因此下面这组命令实际上是通过远程分支接受您当前的分支更改。
# see current branch
$ git branch
...
* branch-a
# rebase preferring current branch changes during conflicts
$ git rebase -X theirs branch-b
Git合并
对于合并,他们和我们的意义是颠倒的。因此,为了在合并过程中获得相同的效果,即保持您当前的分支更改(我们的)超过被合并的远程分支(他们的)。
# assuming branch-a is our current version
$ git merge -X ours branch-b # <- ours: branch-a, theirs: branch-b