One More Powerful Tool πͺ
One More Powerful Tool πͺ κ΄λ ¨
Well, this was the first time in this entire series of Git articles that I use a tool with a graphical user interface. Indeed, graphical interfaces can be very convenient to understand what's going on when you are resolving merge conflicts.
However, like in many other cases, when we need the big guns or really understand what's going on, the command line becomes handy. So let's get back to the command line and learn a tool that can come in handy in more complicated cases.
Again, go back to the state before the merge:
git reset --hard HEAD~
And merge:
git merge paul_branch_4
And say, you are not exactly sure what happened. Why is there a conflict? One very useful command would be:
git log -p -βmerge
As a reminder, git log
shows the history of commits that are reachable from HEAD
. Adding -p
tells git log
to show the commits along the diffs they introduced. The --merge
switch makes the command show all commits containing changes relevant to any unmerged files, on either branch, together with their diffs.
This can help you identify the changes in history that led to the conflicts. So in this example, you'd see:
The first commit we see is "Commit 15", as in this commit John modified everyone.md
, a file that still has conflicts. Next, Git shows "Commit 13", where Paul changed everyone.md
:
Notice that git log --merge
did not mention previous commits that had changed everyone.md
before "Commit 13", as they had not affected the current conflict.
This way, git log
tells you all you need to know to understand the process that got you into the current conflicting state. Cool! π
Using the command line, you can also ask Git to take only one side of the changes β either "ours" or "theirs", even for a specific file.
You can also instruct Git to take some parts of the diffs of one file and another from another file. I will provide links that describe how to do that in the additional resources section below.
For the most part, you can accomplish that pretty easily either manually or from the UI of your favorite IDE.
For now, it's time for a recap.