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.
Note that
git checkout --ours|--theirs
will overwrite the files entirely, by choosing eithertheirs
orours
version, which might be or might not be what you want to do (if you have any non-conflicted changes coming from the other side, they will be lost).If instead you want to perform a three-way merge on the file, and only resolve the conflicted hunks using
--ours|--theirs
, while keeping non-conflicted hunks from both sides in place, you may want to resort togit merge-file
; see details in this answer.Even though this question is answered, providing an example as to what "theirs" and "ours" means in the case of git rebase vs merge. See this link
Git Rebase
theirs
is actually the current branch in the case of rebase. So the below set of commands are actually accepting your current branch changes over the remote branch.Git Merge
For merge, the meaning of
theirs
andours
is reversed. So, to get the same effect during a merge, i.e., keep your current branch changes (ours
) over the remote branch being merged (theirs
).For each conflicted file you get, you can specify
From the
git checkout
docs