Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use three-way diffs for merge conflicts #45

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/using-git/first-time-git-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Once you've installed Git, you should define some important settings before you starting using Git.

```admonish info
We assume that you will want to set the git configuration for all repositories owned by your user.
Therefore, we use the `--global` flag.
Configuration files can be set for a single repository or the whole computer by replacing `--global` with `--local` or `--system` respectively.
```

1. Define your user name and email address.
These details are included in **every commit that you create**.

Expand Down Expand Up @@ -38,6 +44,14 @@ Once you've installed Git, you should define some important settings before you

![Merged branch](../version-control/branch-3.png)

5. Adjust how Git shows merge conflicts:

```sh
git config --global merge.conflictstyle diff3
```

This will be useful when we look at [how to use branches](how-to-use-branches.md) and [how to resolve merge conflicts](how-to-resolve-merge-conflicts.md).

```admonish info
If you use Windows, there are tools that can [improve your Git experience in PowerShell](https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-PowerShell).

Expand Down
22 changes: 22 additions & 0 deletions src/using-git/how-to-resolve-merge-conflicts.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ Note that this two-day diff shows:

Each conflict is surrounded by `<<<<<<<` and `>>>>>>>` markers, and the conflicting changes are separated by a `=======` marker.

If we instruct Git to use a three-way diff (see [first-time Git setup](first-time-git-setup.md)), the conflict will be reported slightly differently:

```diff
diff --cc test.txt
index 18712c4,bc576a6..0000000
--- a/test.txt
+++ b/test.txt
@@@ -1,3 -1,3 +1,7 @@@
First line
++<<<<<<< ours
+A different second line
++||||||| base
++Second line
++=======
+ My new second line
++>>>>>>> theirs
Third line
```

In addition to showing "our" changes and "their changes", this three-way diff also shows the **original lines**, between the `|||||||` and `=======` markers.
This extra information can help you decide how to best resolve the conflict.

## Resolving the conflicts

We can edit `test.txt` to reconcile these changes, and the commit our fix.
Expand Down
Loading