diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 17138a2d342c1ac94e1904fa4784c6894806b175..58e37ff13e9387b73e2305907985d078226f9215 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,8 +26,8 @@ build_printable_episodes: script: - cd episodes - pandoc --from markdown --to docx --out 01-using-shell.docx 01-using-shell.md - - pandoc --from markdown --to docx --out 08-remotes-in-gitlab.docx 08-remotes-in-gitlab.md - - pandoc --from markdown --to docx --out 09-conflicts.docx 09-conflicts.md + - pandoc --from markdown --to docx --out 08-conflicts.docx 08-conflicts.md + - pandoc --from markdown --to docx --out 09-remotes-in-gitlab.docx 09-remotes-in-gitlab.md - pandoc --from markdown --to docx --out 10-collaboration-with-others.docx 10-collaboration-with-others.md tags: - docker diff --git a/README.md b/README.md index 9ca4fe085f8037f89bb3238b48c65c9ad29d4710..33b80efeaa7644a974305fcdd17ff7ce71da9382 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ Please bring your laptop including a Web browser, a text editor, and a recent [G 1. [Ignoring Things](https://swcarpentry.github.io/git-novice/06-ignore/index.html) <br />*Exercises:* [Ignoring Nested Files](https://swcarpentry.github.io/git-novice/06-ignore/index.html#ignoring-nested-files), [The Order of Rules](https://swcarpentry.github.io/git-novice/06-ignore/index.html#the-order-of-rules) -1. [Remotes with GitLab](episodes/08-remotes-in-gitlab.md) -1. [Conflicts](episodes/09-conflicts.md) +1. [Conflicts](episodes/08-conflicts.md) +1. [Remotes with GitLab](episodes/09-remotes-in-gitlab.md) 1. [Collaboration with Others](episodes/10-collaboration-with-others.md) ### Schedule diff --git a/episodes/08-conflicts.md b/episodes/08-conflicts.md new file mode 100644 index 0000000000000000000000000000000000000000..d411930720ae00f6091157753609e8b5af278136 --- /dev/null +++ b/episodes/08-conflicts.md @@ -0,0 +1,124 @@ +<!-- +SPDX-FileCopyrightText: 2020 German Aerospace Center (DLR) + +SPDX-License-Identifier: CC-BY-4.0 +--> + +# Conflicts + +In this episode, we create [a conflict](https://swcarpentry.github.io/git-novice/fig/conflict.svg) and resolve it. +In addition, we briefly introduce the typically used concepts of `branching` and `merging`. +Please see [the original Conflict episode](https://swcarpentry.github.io/git-novice/09-conflict/index.html) for further details. +In addition, [conflicts.pptx](extras/conflicts.pptx) shows an animation of all performed steps. + +## Background + +- `Branching` is an important concept in Git. + - A `branch` is a specific series of commits in the repository. + - The `master` branch reflects the current state ("truth") of the repository + and typically acts as synchronization point for starting off new work and re-integrating finished work. + - Every Git repository can contain as many branches as you want. + - Every Git repository can have different branches. + - Branches can be shared between Git repositories. +- Typically, you start a new piece of work by creating a new `branch` out of the `master` branch. +- Once, you are finished with your work you re-integrate it by `merging` your working branch back into the `master` branch. +- When re-integrating your work, it might happen that `conflicts` occur because someone else changed the same lines as you. + +## Configure some Useful Details + +- Configure a GitLab-like graph view in the Shell: `git config alias.graph "log --oneline --graph --all --decorate"` +- Configure a [known editor](https://git-scm.com/book/en/v2/Appendix-C%3A-Git-Commands-Setup-and-Config#_core_editor) for later conflict resolution: `git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"` + - View diff while writing commit message `git config --global commit.verbose true` + - Test with `git config --global --edit` + +## Create a new Branch and start your Work + +- Show the existing branches + - `git branch --all` + - Explain the labels `master` and `HEAD` +- Show graph of the repository + - Draw state of the repository + - Verify with `git graph` + +``` +o - o <- HEAD, master +``` + +- Create a new branch + - `git branch mummy-info` +- Show what changed + - Verify with `git branch` and `git graph` + - Explain that `*` marks where the HEAD is pointing to + +``` +o - o <- HEAD, master, mummy-info +``` + +- Switch to the newly created branch + - `git checkout mummy-info` (Git version >= 2.23 supports: `git switch <BRANCH NAME>`) + - Verify with `git branch` +- Edit the file `mars.txt` and commit the changes + - Add a new sentence at the end of the file: `Mummy will appreciate sand storms on Mars` + - Adapt the first line and attach at its end: ` (for Dracula)` + - Add & commit it: `git add mars.txt`, `git commit -m "Add advantages for the Mummy"` + - Verify with `git graph` + +``` + o <- HEAD, mummy-info + / +o - o <- master +``` + +## Prepare the Conflict + +- Switch back to the `master` branch + - `git checkout master` (Git version >= 2.23 supports: `git switch <BRANCH NAME>`) + - Verify with `git branch` and `git graph` +- Edit the file `mars.txt` and commit the changes + - Add a new sentence at the end of the file: `Generating solar energy is less effective on Mars` + - Add & commit it: `git add mars.txt`, `git commit -m "Add information about energy generation"` + - Verify with `git graph` + +``` + o <- mummy-info + / +o - o - o <- HEAD, master +``` + +## Merge and Resolve the Conflict + +- Merge the working branch (`mummy-info`) into the `master`branch + - `git merge mummy-info` + - Explain the output and the consequences +- Resolve the conflict manually with the help of the editor by editing the `<<< ... === ... >>>` section and removing the conflict markers +- Mark the conflict as resolved: + - `git add mars.txt` + - `git commit` (without commit message => explain interactive commit with default message) +- Show local commit log: + - `git graph` + - Highlight the split with coexisting commits + - Highlight that no version/commit is lost in a merge + +``` + o <- mummy-info + / \ +o - o - o - o <- HEAD, master +``` + +- Clean up the local branch + - Delete the branch `git branch -d mummy-info` + - Verfiy with `git branch` and `git graph` + +``` + o + / \ +o - o - o - o <- HEAD, master +``` + +## Key Points + +- Git can merge diverging files line-based + - unless the same line is changed in different ways +- Resolve conflicts by editing the `<<< ... === ... >>>` sections + - then remove markers, `git add` and `git commit` +- Shell prompt and command outputs include hints and instructions diff --git a/episodes/09-conflicts.md b/episodes/09-conflicts.md deleted file mode 100644 index ef0e9894ba537b6f4865272098ebeab425fd0ecd..0000000000000000000000000000000000000000 --- a/episodes/09-conflicts.md +++ /dev/null @@ -1,63 +0,0 @@ -<!-- -SPDX-FileCopyrightText: 2020 German Aerospace Center (DLR) - -SPDX-License-Identifier: CC-BY-4.0 ---> - -# Conflicts - -In this episode, we create [a conflict](https://swcarpentry.github.io/git-novice/fig/conflict.svg) and resolve it. -Please see [the original Conflict episode](https://swcarpentry.github.io/git-novice/09-conflict/index.html) for further details. -In addition, [conflicts.pptx](extras/conflicts.pptx) shows an animation of all performed -steps. - -## Configure some Useful Details - -- Configure a GitLab-like graph view in the Shell: `git config alias.graph "log --oneline --graph --all --decorate"` -- Configure a [known editor](https://git-scm.com/book/en/v2/Appendix-C%3A-Git-Commands-Setup-and-Config#_core_editor) for later conflict resolution: `git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"` - - View diff while writing commit message `git config --global commit.verbose true` - - Test with `git config --global --edit` - -## Create a Conflict - -- In the remote repository: - - Change the sentence on first line to `Cold, dry and rocky, but everything is my favorite color` in `mars.txt` - - Add a new sentence: `Mummy will appreciate sand storms on Mars` to `mars.txt` - - Commit the changes with the commit message `"Prepare merge conflict on GitLab"` - - Show GitLab's `/commits` or `/graph` pages -- In the local repository: - - Add a new sentence: `Generating solar energy is less effective on Mars` to `mars.txt` - - Add & commit it: `git add mars.txt` & `git commit -m "Prepare merge conflict locally"` -- Show local commit log: - - `git graph` -- Show that a push to remote fails: - - `git push origin master` - - Explain reasons - - Optional: `git fetch -v` - -## Resolve the Conflict - -- Pull from remote repository: - - `git pull` -- Perform manual merge with the editor by editing the `<<< ... === ... >>>` section and removal of these conflict markers -- Mark the conflict as resolved: - - `git add mars.txt` - - `git commit` (without commit message => explain interactive commit with default message) -- Show local commit log: - - `git graph` - - Highlight the split with coexisting commits - - Highlight that no version/commit is lost in a merge - - Highlight that `origin/master` is behind `master` (local Git repository) -- Push result to remote repository: - - `git push` -- Show local commit log: - - `git graph` - - Highlight that `origin/master` and `master` (local Git repository) are equal - -## Key Points - -- Git can merge diverging files line-based - - unless the same line is changed in different ways -- Resolve conflicts by editing the `<<< ... === ... >>>` sections - - then remove markers, `git add` and `git commit` -- Shell prompt and command outputs include hints and instructions diff --git a/episodes/08-remotes-in-gitlab.md b/episodes/09-remotes-in-gitlab.md similarity index 100% rename from episodes/08-remotes-in-gitlab.md rename to episodes/09-remotes-in-gitlab.md