git - To resolve a merge conflict, how do I see what change the other branch was making? -
i pulled latest code repository git pull --rebase
. local commit conflicts 1 of remote commits. file in question has merge markers in it, can compare version version, want know change other version trying make? want diff other change our common ancestor. how do that?
(edit: gah, had broken diagram , description, let's fix it:)
this command show everything changed, , might want isolate changes specific commit or set of commits and/or files within commits, consider doing:
$ git diff $(git merge-base master origin/master) origin/master
(assuming you're on branch master
). tells git compare common ancestor commit "their" head commit.
here's rough sketch of what's going on. suppose started commits a
, b
, , c
obtained origin
(the repo cloned). made commits d
, e
, made f
, g
. you're in middle of conflicted rebase. (i've assumed here change in d
rebased successfully, giving commit d'
, , problem @ e
.) +i,w
means there stuff in index and/or working directory not yet committed—that's commit conflicts, need resolve.
d - e <-- master / - b - c d' +i,w <-- head (detached) \ / f - g <-- origin/master
in case, git merge-base master origin/master
finds commit c
, common point rebase.
meanwhile origin/master
names commit g
. so:
git diff <name-of-commit-c> origin/master
shows did, in both commits f
, g
(compares contents of g
contents of c
). of course, can use git log
find individual commits, or name them names origin/master~1
. can git show origin/master
@ recent change g
, , git show origin/master~1
show change f
.
eventually, if once resolve conflicts , git rebase --continue
, reaches end, git move branch label (master
) head
points, , set head
refer master
, rather being "detached". or, if use git rebase --abort
abandon new chain , restore old master
(which can re-rebase
later).
(incidentally, 1 case graphical tools gitk
come in handy. bring gitk --all
or gitk head master origin/master
on conflicted rebase , it's easy see conflicting commit is.)
for tough merge cases, there's git-imerge, have not used (yet) looks nice.
Comments
Post a Comment