diff --git a/2019/2019-09-24_advancedGitTraining/slides/chPick.md b/2019/2019-09-24_advancedGitTraining/slides/chPick.md index 63d3bdbc3016c660a8a08b6bb04430863d4d0a80..f865ef90cf65445ac76102a5573bfe95b20fea20 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/chPick.md +++ b/2019/2019-09-24_advancedGitTraining/slides/chPick.md @@ -1,7 +1,7 @@ # Cherry-picking -* Cherry-pick allows to pick one (or more) specific commits from a list of commits. -* Cherry picking only picks the selected commit(s), not everything up to that commit. +* Cherry-picking allows to pick one (or more) specific commits from a list of commits. +* Only the chosen commit(s) are picked, not everything up to that commit. <div style="top: 8em; left: 25%; position: absolute;"> <img src="slides/img/cherryPick.png" height=500px> @@ -11,8 +11,9 @@ # Example (1) -* Create and commit two files in the `develop `branch +* Create and commit two files in the `develop ` branch ```bash +$ git checkout develop $ echo "# Venue details" > location.md $ # add and commit the file location.md $ echo "# Speakers" > speakers.md @@ -46,26 +47,37 @@ $ git push origin myBranch # Partial chery-picking * Partial cherry-picking allows you to unpack the changes from a commit. + * Imagine you committed many files, and you want to remove certain files. + * In practice: + - You commited all files, and you realize that there is your data inside! + - You have committed accidentally sensitive data, such as your password + - You committed hidden files, for instance `.DS_Store` files + - ... + # Example (1) +* Hard reset the `myBranch` branch: +```bash +$ git checkout myBranch +$ git reset --hard HEAD~2 # do not preserve files +``` + * Reset the `develop` branch: ```bash $ git checkout develop -$ git reset HEAD~2 +$ git reset HEAD~2 # preserve files ``` * Add the `location.md` and the `speakers.md` files as 1 commit: ```bash -$ echo "# Venue details" > location.md -$ echo "# Speakers" > speakers.md $ git add location.md speakers.md $ git commit -m "add location and speakers files" ``` @@ -83,7 +95,7 @@ $ git status ``` Now, remove the file `location.md`: ```bash -$ git restore --staged location.md +$ git restore --staged location.md # old version of git: $ git reset HEAD location.md $ rm location.md ``` Commit the changes: diff --git a/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md b/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md index 99cbf122ed592ebc5fa5bb28ea394bef0828da94..bfaf86e10481897bda7a15e91de88bbe4edfa92d 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md +++ b/2019/2019-09-24_advancedGitTraining/slides/gettingStarted.md @@ -1,4 +1,4 @@ -# Getting Started +# Getting Started (1) Make sure that your git is configured properly: ```bash @@ -20,25 +20,29 @@ 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 -# add upstream URL -$ git remote add upstream ssh://git@git-r3lab-server.uni.lu:8022/R3/school/git/advanced-practice.git -$ git fetch upstream -``` -Check the remotes -```bash -$ git remote -v -``` +# Getting Started (2) -Create your own branch `myBranch` based on the `develop` branch from `usptream` using the `-b` flag -```bash -$ git checkout -b myBranch upstream/develop -``` +* Please generate your SSH before with `$ ssh-keygen -t rsa` and set it in Gitlab! + +* Add a remote `upstream` + ```bash + $ cd advanced-practice + # add upstream URL + $ git remote add upstream ssh://git@git-r3lab-server.uni.lu:8022/R3/school/git/advanced-practice.git + $ git fetch upstream + ``` +* Check the remotes with: + ```bash + $ git remote -v + ``` + +* Create the `develop` branch and your own branch `myBranch` based on the `develop` branch from `upstream` using the `-b` flag + ```bash + $ git checkout -b develop upstream/develop + $ git checkout -b myBranch + ``` diff --git a/2019/2019-09-24_advancedGitTraining/slides/rebase.md b/2019/2019-09-24_advancedGitTraining/slides/rebase.md index a985df74a86ce5008ec3eb7446392ebf60bd27b2..8fc767e99eb86728f0b861896a443c9ff3078568 100644 --- a/2019/2019-09-24_advancedGitTraining/slides/rebase.md +++ b/2019/2019-09-24_advancedGitTraining/slides/rebase.md @@ -69,6 +69,8 @@ $ git log # Interactive Rebasing - flag `-i` +* An interactive rebase is performed with the `-i` flag: + ```bash git rebase -i <branch> ``` @@ -98,7 +100,7 @@ $ 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 $ # add and commit the file roberta.md with the message 'add roberta to attendee list' -$ git push origin yourBranch +$ git push origin myBranch ``` Now, we want to: @@ -131,7 +133,8 @@ $ pick abcdef0 add roberta to attendee list $ reword 1234567 add william to attendee list $ fixup abcdef0 add roberta to attendee list ``` -* Change the message of commit `1234567` to `Add William and Roberta to the attendee list`. +* Edit by typing `i` +* Change the message of commit `1234567` to `Add William and Roberta to the attendee list` * Save with `:wq`