Skip to content
Snippets Groups Projects
Verified Commit 94a4f27b authored by Laurent Heirendt's avatar Laurent Heirendt :airplane:
Browse files

installation instructions for kdiff3, and example for solving conflict on local merge

parent 82911dea
No related branches found
No related tags found
No related merge requests found
# Theory: Conflict resolution
# Conflict resolution
* A conflict emerges when two files push two different changes
to a one target branch
* A conflict occurs when two changes change the same line in a file
* Some conflict may be resolved automatically, but major conflicts
always need to be resolved manually
* Tools exist to streamline conflict resolutions, we use kdiff3
* Tools exist to streamline conflict resolutions, we use `kdiff3`
* Conflicts can happen during `merge`, `cherry-pick`, and `rebase`
# Practical: Conflict resolution using kdiff3
* create a branch named changeMicheal and in the editor you change
the content of `Michael.md`:
# Example 1: Conflict resolution when locally merging (1)
* Checkout the branch `myNewBranch` and change the file `template.md`:
```bash
$ git checkout develop
$ git checkout -b changeMichael
$ git checkout myNewBranch
```
Change Michael file...
* Use your favorite editor and type:
```bash
$ git fetch upstream
$ git checkout develop
$ git merge upstream/develop
# Advanced git training course
## Firstname Lastname
```
summary:
michael.md on develop:
* Add and commit that change.
* Checkout the branch `myBranch` and change the file `template.md`:
```bash
# Advanced git training -- Course
## Firstname Lastname
```
# Michael
* Then, save, add, and commit that change.
# Example 1: Conflict resolution when locally merging (2)
* Merge the `myNewBranch` into the `myBranch` branch:
```bash
$ git merge myNewBranch
```
michael.md on changeMichael (example)
* A conflict appears:
```bash
$ git merge myNewBranch
Auto-merging attendees/template.md
CONFLICT (content): Merge conflict in attendees/template.md
Automatic merge failed; fix conflicts and then commit the result.
```
## Michael Evans
* Start the merge tool:
```
$ git mergetool
```
# Example 1: Conflict resolution when locally merging (3)
# Practical: Conflict resolution using kdiff3
* This opens kdiff3 if it was properly set up. There are 3 versions:
- **A**: version on `myBranch` before the recent change.
- **B**: version on `myNewBranch`
- **C**: version on `myBranch` after the recent change
If then there is a rebase done on develop:
* Resolve the conflict and save. Then:
```bash
$ git rebase develop
$ git merge --continue
```
A conflict should emerge
* When facing the merge conflict message, use the command
* If you check the status, you will find a `.orig` file. This is a backup and contains the conflict.
```bash
$ git mergetool
$ git status
$ cat template.md.orig
```
* This opens kdiff3 if it was properly set up. Selecting A will keep the changes of the target branch,
while B will keep your changes. Selecting A and B will combine both changes to the merged file.
* If you do not need anymore the backup file, you can remove it.
* You can either `rm` the `.orig` file, or you can use `git clean -fdx`. **Tip:** use `--dry-run` first to list all files that would be deleted.
# Example 2: Conflict resolution when cherry-picking (1)
# Practical: Conflict resolution using kdiff3
* After resolving the conflicts, continue in your terminal
```bash
......@@ -70,8 +96,3 @@ $ git rebase --continue
$ git status
```
* It shows you a `.orig` file. This `.orig` file contains information about the conflict.
```bash
$ rm _attendees/michael.md.orig
```
* You can either `rm` the `.orig` file, or you can use `git clean -fdx`.
\ No newline at end of file
......@@ -27,6 +27,28 @@ $ git checkout -b <mybranch> upstream/develop
# Installing the mergetool `kdiff3`
* Download it here: https://sourceforge.net/projects/kdiff3/files/
* The downloadable file should match your OS
* Setting up `kdiff3`:
```bash
$ git config --global --add merge.tool kdiff3
$ git config --global --add mergetool.kdiff3.path "<kdiff3 path>"
$ git config --global --add mergetool.kdiff3.trustExitCode false
$ git config --global --add diff.guitool kdiff3
$ git config --global --add difftool.kdiff3.path "<kdiff3 path>"
$ git config --global --add difftool.kdiff3.trustExitCode false
```
* omit `""` when setting up on Linux or macOS
# A note on common commands:
This workshop will not cover in detail the following commands, assuming you are familiar with them:
......
# Installing kdiff3
* Recommended tool: KDiff3
* Download it here: https://sourceforge.net/projects/kdiff3/files/
* The downloadable file should match your OS
# Setting up kdiff3
```bash
git config --global --add merge.tool kdiff3
git config --global --add mergetool.kdiff3.path " <Kdiff3 path> "
git config --global --add mergetool.kdiff3.trustExitCode false
git config --global --add diff.guitool kdiff3
git config --global --add difftool.kdiff3.path " <Kdiff3 path> "
git config --global --add difftool.kdiff3.trustExitCode false
```
* omit `""` when setting up on linux or mac
\ No newline at end of file
......@@ -9,6 +9,5 @@
{ "filename": "chPick.md" },
{ "filename": "merge.md" },
{ "filename": "conflict.md" },
{ "filename": "kdiff3Install.md" },
{ "filename": "thanks.md" }
]
......@@ -5,6 +5,7 @@
* In practice, this is very useful if you 'just want to try out something', or 'draft' something
# Example (1)
* Create a new branch from your `myBranch` branch:
......@@ -21,6 +22,8 @@ $ echo "# Gustav Bergen" > gustav.md
$ # add and commit the file gustav.md
```
# Example (2)
* Check the `log` of the `myNewBranch` and `myBranch` branches:
......
# Overview
1. Amend last commit
1. Installation and getting started
2. Resetting to a previous commit
2. Amend last commit
3. Reverting commits
3. Resetting to a previous commit
4. Rebasing in Git
4. Reverting commits
5. Git cherry-picking
5. Rebasing in Git
6. Merging branches
6. Git cherry-picking
7. Conflict Resolution
7. Merging branches
8. Conflict Resolution
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment