From ef141452fba315e0f41b8cc6542d7fb6c46090c6 Mon Sep 17 00:00:00 2001 From: laurentheirendt <laurent.heirendt@uni.lu> Date: Tue, 24 Sep 2019 10:08:44 +0200 Subject: [PATCH] 1st round of review --- .../slides/amend.md | 9 +++-- .../slides/gettingStarted.md | 28 +++++++++++++--- .../slides/rebase.md | 33 ++++++++----------- .../slides/reset.md | 18 ++++++---- .../slides/revert.md | 13 ++++---- 5 files changed, 60 insertions(+), 41 deletions(-) diff --git a/2019/2019-09-24_advancedGitTraining/slides/amend.md b/2019/2019-09-24_advancedGitTraining/slides/amend.md index b419db3f..9f4974ca 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/amend.md +++ b/2019/2019-09-24_advancedGitTraining/slides/amend.md @@ -52,10 +52,13 @@ $ git status * With the changes staged use the following command to commit the changes into the previous commit: ```bash -$ cd ../ # change directory one up if required -$ git add attendees/myName.md +$ git add myName.md $ git commit --amend --no-edit ``` +* Check the commit content: +```bash +$ git show HEAD +``` + * This will create and commit a new commit with the staged changes added and the same commit message. -* (Force) push your changes to your branch `myBranch` diff --git a/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md b/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md index b64e2b85..99cbf122 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md +++ b/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md @@ -1,5 +1,18 @@ # Getting Started +Make sure that your git is configured properly: +```bash +$ git config --global user.name "Firstname Lastname" +$ git config --global user.email "first.last@uni.lu" +``` + +Test whether your username and email have been registered + +```bash +$ git config --list +``` + + Fork and then clone the tutorial repository <a href="https://git-r3lab.uni.lu/R3/school/git/advanced-practice">https://git-r3lab.uni.lu/R3/school/git/advanced-practice</a> @@ -7,6 +20,8 @@ Fork and then clone the tutorial repository $ git clone ssh://git@git-r3lab-server.uni.lu:8022/<first.last>/advanced-practice.git ``` +**Note:** Please generate your SSH before with `$ ssh-keygen -t rsa` and set it in Gitlab! + Add a remote upstream ```bash $ cd advanced-practice @@ -22,17 +37,15 @@ $ git remote -v Create your own branch `myBranch` based on the `develop` branch from `usptream` using the `-b` flag ```bash -$ git checkout -b <mybranch> upstream/develop +$ git checkout -b myBranch upstream/develop ``` -# Installing the mergetool `kdiff3` +# Install the mergetool `kdiff3` * Download it here: http://kdiff3.sourceforge.net/ -* The downloadable file should match your OS - * Setting up `kdiff3`: ```bash @@ -42,6 +55,13 @@ $ git config --global --add mergetool.kdiff3.path "<kdiff3 path>" * omit `""` when setting up on Linux or macOS +**Note**: On UNIX, you can find the path of `kdiff3` by typing: +```bash +$ which kdiff3 +``` +On Windows, the path might be `C:/Program Files/KDiff3/kdiff3.exe`. + + # A note on common commands: diff --git a/2019/2019-09-24_advancedGitTraining/slides/rebase.md b/2019/2019-09-24_advancedGitTraining/slides/rebase.md index b4a262c6..a985df74 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/rebase.md +++ b/2019/2019-09-24_advancedGitTraining/slides/rebase.md @@ -1,6 +1,6 @@ # Rebasing (1) -* Git rebase enables to forward your commits +* `git rebase` enables to forward your commits * Move/combine a sequence of commits to a new base commit * Avoid discrepancies when multiple people work on the same project * Linear git history (no merge commits) @@ -26,10 +26,11 @@ Imagine the following situation: # Example (1): +* A merge request against `develop` is still open. Repository maintainer: review, and merge it. + * Create a file in your branch `myBranch` ```bash $ git checkout myBranch # if necessary -$ cd attendees $ echo "# List of attendees" > list.md $ # add and commit the file ``` @@ -88,11 +89,11 @@ git rebase -i <branch> # Example 1: Reword and fixup (1) -* Create and switch to your own branch +* Switch to your own branch `myBranch` * Add and commit two files to this branch: ```bash -$ cd attendees +$ # git checkout myBranch && cd attendees $ echo "# William Odell" > william.md $ # add and commit the file william.md with the message 'add william to attendee list' $ echo "# Roberta Ross" > roberta.md @@ -103,7 +104,9 @@ $ git push origin yourBranch Now, we want to: - Reword the first commit's message to: `Add William and Roberta to attendee list` + - Combine the second and first commit into one + - Omit the commit message of the second commit. @@ -111,41 +114,31 @@ Now, we want to: # Example 1: Reword and fixup (2) -Perform an interactive rebase with the two last commits: +* Perform an interactive rebase with the two last commits: ```bash $ git rebase -i HEAD~2 ``` -The prompt shows up: +* The dialog shows up (example): ```bash $ pick 1234567 add william to attendee list $ pick abcdef0 add roberta to attendee list ``` -The keywords `pick` can now be changed to `reword` and `fixup` respectively: +* The keywords `pick` can now be changed to `reword` and `fixup` respectively: ```bash $ reword 1234567 add william to attendee list $ fixup abcdef0 add roberta to attendee list ``` - -**Note:** The SHA1s of each commit are different. - -Upon confirming, change the message of commit 1234567: -```bash -$ Add Micheal and Kevin to the attendee list -``` - -Then use force-push to push your changes: -```bash -$ git push origin myBranch -f -``` +* Change the message of commit `1234567` to `Add William and Roberta to the attendee list`. +* Save with `:wq` # Example 2: Pick and squash (2) -* If you wante to keep both commit messages in one commit, change the action to `squash` +* If you want to **keep** both commit messages in one commit, change the action to `squash` ```bash $ pick 1234567 add william to attendee list $ squash abcdef0 add roberta to attendee list diff --git a/2019/2019-09-24_advancedGitTraining/slides/reset.md b/2019/2019-09-24_advancedGitTraining/slides/reset.md index 4f72b8a4..02f423eb 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/reset.md +++ b/2019/2019-09-24_advancedGitTraining/slides/reset.md @@ -1,6 +1,6 @@ # Reset a branch -* Enables to reset back to a previous commit +* Enables to reset a branch back to a previous commit * Discards ALL commits made after the selected commit HEAD * This happens often in **practice**: @@ -12,10 +12,11 @@ * Start by committing two files: ```bash -$ cd attendees +# commit first file ... $ echo "# CV of Firstname Lastname" > myCV.md $ git add myCV.md $ git commit -m "add cv for Firstname Lastname" +# commit second file ... $ echo "# Biography of Firstname Lastname" > myBio.md $ git add myBio.md $ git commit -m "add biography for Firstname Lastname" @@ -31,25 +32,28 @@ $ git log # Example: Hard reset of a branch (2) -* Use the `reset --hard` command in order to undo the faulty commit: +* Use the `reset --hard` command in order to undo the commit with `<SHA1>: ```bash $ git reset --hard <SHA1> ``` * Check what happened in the log -* Force push your branch (overwrite the history) +* Force push your branch (overwrite the history) with `-f`: +```bash +$ git push origin myBranch -f +``` # Notes -Alternatively, you can also remove the last commit: +* Alternatively, you can also remove the last commit: ```bash $ git reset --hard HEAD~1 ``` -With a `--hard` reset, the index and the working tree are reset. +* With a `--hard` reset, the index and the working tree are reset. -If you omit the `--hard` flag, a mixed reset is made. This resets the index, but not the working tree +* If you omit the `--hard` flag, a mixed reset is made. This resets the index, but not the working tree ```bash $ git reset HEAD~1 ``` \ No newline at end of file diff --git a/2019/2019-09-24_advancedGitTraining/slides/revert.md b/2019/2019-09-24_advancedGitTraining/slides/revert.md index 1abc41c9..da625467 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/revert.md +++ b/2019/2019-09-24_advancedGitTraining/slides/revert.md @@ -1,6 +1,7 @@ # Reverting a commit * Enables the deletion of committed commits by reverting the changes. + * A trace is kept in history of the original commit and the reverted one. @@ -9,17 +10,15 @@ * On your branch, create and commit a file: ```bash -$ cd attendees $ echo "# Grades for Firstname Lastname" > grades.md $ git add grades.md $ git commit -m "File with grades for Firstname Lastname" ``` -* check the commit log and copy the SHA1: -```bash -$ git log -``` -* Use the `git revert` command to undo this selected commit: +* Note down the `SHA1` by checking the `log` + +* Use the `git revert` command to undo that commit: ```bash -$ git revert <sha1> +$ git revert <SHA1> ``` +* This will open a dialog (`vim`-like editor). Exit with `:wq` \ No newline at end of file -- GitLab