5.2. Merge conflicts.md - shinokada/gitnotes GitHub Wiki

Merge Conflicts

Resolving merge conflicts

To roll back and start over, reset your working environment with the following command:

❯ git reset --hard HEAD

This reverts your working environment back to match HEAD, which, in this case, is the latest commit of your current branch.

Better way to view merge conflicts (Three-way merge data)

Tto show you the three-way merge data:

❯ git config merge.conflictstyle diff3

To change back to the default merge conflict tagging:

❯ git config --unset merge.conflictstyle

Then merge:

❯ git merge yUI
❯ git status
On branch zIntegration
Your branch is up to date with 'origin/zIntegration'.

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
        new file:   css/main.css

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   index.html

Untracked files:

A consolidated git status

Add the -s (--short) and -b (--branch) options to git status to get a consolidated view of the situation:

❯ git status -sb
## zIntegration...origin/zIntegration
A  css/main.css
UU index.html
  • One file, css/main.css added (A) on your local branch
  • Two revisions of a file that are unmerged (U). This is the original index.html from the zIntegration branch, and the index.html from the yUI branch.

Editing conflicts

<<<<<<< HEAD

<section>
...
<pre id="magic-square-display">

||||||| 69670e7

<section>
...
<pre>
=======

<section class="box">
...
<pre class="flex-item" >

>>>>>>> yUI

||||||| 69670e7 shows you the hash of the common ancestor of both Yasmin and Zach’s changes. First your change, common ancestor, and then incoming change.

Edit: delete the entire first two blocks from the conflicted section, from <<< HEAD all the way to ===. Then, delete the >>> yUI line as well.

Save the file.

Completing the merge operation

❯ git add index.html
❯ git status -sb
## zIntegration...origin/zIntegration
A  css/main.css
M  index.html

One new file (A) and one modified file (M).

❯ git commit

Check it on a browser. First, delete the yUI branch:

❯ git branch -d yUI

Switch to the main branch:

❯ git checkout main

Merge the zIntegration branch:

❯ git merge zIntegration

Delete the zIntegration branch:

❯ git branch -D zIntegration
⚠️ **GitHub.com Fallback** ⚠️