diff --git a/2019/2019-09-24_advancedGitTraining/slides/conflict.md b/2019/2019-09-24_advancedGitTraining/slides/conflict.md index a65d340d9f2d145479dba77a1e8be125321f313a..1cccc73a0501eebc83967e7b8b07fb62a93e4f81 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/conflict.md +++ b/2019/2019-09-24_advancedGitTraining/slides/conflict.md @@ -1,65 +1,91 @@ -# 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 diff --git a/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md b/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md index e064d0ea7b771d280489d4f8fcd5774405da668d..bec315ccb0eb893185a5dd38a74311c4c0c97056 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md +++ b/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md @@ -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: diff --git a/2019/2019-09-24_advancedGitTraining/slides/kdiff3Install.md b/2019/2019-09-24_advancedGitTraining/slides/kdiff3Install.md deleted file mode 100644 index 7bff832f9ef17ce95d81be4fd24f484b25712130..0000000000000000000000000000000000000000 --- a/2019/2019-09-24_advancedGitTraining/slides/kdiff3Install.md +++ /dev/null @@ -1,23 +0,0 @@ -# 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 diff --git a/2019/2019-09-24_advancedGitTraining/slides/list.json b/2019/2019-09-24_advancedGitTraining/slides/list.json index bcd5e588ada5a1214143b484f7aa9b6a67fa7147..d14c9ece6715e51855ca0da8c485cd55fbd3a13a 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/list.json +++ b/2019/2019-09-24_advancedGitTraining/slides/list.json @@ -9,6 +9,5 @@ { "filename": "chPick.md" }, { "filename": "merge.md" }, { "filename": "conflict.md" }, - { "filename": "kdiff3Install.md" }, { "filename": "thanks.md" } ] diff --git a/2019/2019-09-24_advancedGitTraining/slides/merge.md b/2019/2019-09-24_advancedGitTraining/slides/merge.md index c3e00b3f2d1eee39c41879aab21735187d717cde..4ee132e758d160d5dac13713f32c7d33e22b6329 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/merge.md +++ b/2019/2019-09-24_advancedGitTraining/slides/merge.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: diff --git a/2019/2019-09-24_advancedGitTraining/slides/overview.md b/2019/2019-09-24_advancedGitTraining/slides/overview.md index 556caad9afaab3c2328c1a09ed0b617bc0a910f1..3b769f404405e775441c2d5d5492abf7a39ef80c 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/overview.md +++ b/2019/2019-09-24_advancedGitTraining/slides/overview.md @@ -1,15 +1,17 @@ # 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