Skip to content
Snippets Groups Projects
Commit 53f15bad authored by Laurent Heirendt's avatar Laurent Heirendt :airplane:
Browse files

Merge branch '2019-08-21_testCourse' into 'develop'

2019 08 21 test course

See merge request R3-core/outreach/presentations-internal!41
parents 9615dcc6 d0e17efd
No related branches found
No related tags found
No related merge requests found
Showing
with 197 additions and 1 deletion
[submodule "theme"]
path = theme
url = https://git-r3lab.uni.lu/R3/outreach/theme.git
url = https://git-r3lab.uni.lu/R3/outreach/theme.git
# Theory: Git Amend
* Enables to change the specifics of the commit on HEAD (the last commit)
\ No newline at end of file
# Practical: Git Amend
* Start by creating and committing a file
```bash
$ echo "This file contains errors and needs to be amended" > amend.txt
$ git add amend.txt
$ git commit -m "this file needs to be amended"
```
* Check the commit
```bash
$ git log
```
\ No newline at end of file
# Practical: Git Amend - Commit Message
* Verify that your staging area is clear:
```bash
$ git status
```
* use the `commit --amend` with the `-m` flag to edit only the commit message:
```bash
$ git commit --amend -m "This commit title has been amended"
```
* See the commit message in the log has changed:
```bash
$ git log
```
# Practical: Git Amend - Commit Content
* In your editor, change the text in the amend.txt file:
```bash
"This file's content have been corrected"
```
* Check if the changed file is in the staging area:
```bash
$ git status
```
* With the changes stages use the following command to commit the changes into the previous commit:
```bash
$ git commit --amend -no-edit
```
* This will create and commit a new commit with the staged changes added.
* Force push your changes to develop
# Theory: Git Cherry-picking
* It enables the user to pick specific commits from a list of commits.
Careful!
Cherry picking only picks the selected commit,
not everything up to that commit.
<div style="top: 15em; left: 30%; position: absolute;">
<img src="slides/img/cherryPick.png">
</div>
\ No newline at end of file
# Practical: Git Cherry-picking
* In your branch, create and commit a reference file
```bash
$ echo "This is the start of a commit chain" > reference.txt
$ git add reference.txt
$ git commit origin myBranch
```
* Create and commit two files in the develop branch
```bash
$ echo "This is a commit to keep" > keep.txt
$ git add keep.txt
$ git commit origin develop
$ echo "Ignore this commit" > ignore.txt
$ git add ignore.txt
$ git commit origin develop
```
\ No newline at end of file
# Practical: Git Cherry-picking
* Check the commit reference of the two commits in develop
* Chose the commit to keep and add it to your branch
```bash
$ git checkout myBranch
$ git cherry-pick <commit reference>
```
* Check the log again and see if the changes were applied correctly
* push the changes to the develop branch
```bash
$ git push origin myBranch -f
```
* The `-f` flag is used to force push into develop
\ No newline at end of file
# Theory: Conflict resolution
* A conflict emerges when two files push two different changes
to a one target branch
* Some conflict may be resolved automatically, but major conflicts
always need to be resolved manually
* Tools exist to streamline conflict resolutions, we use kdiff3
\ No newline at end of file
# Practical: Conflict resolution using kdiff3
* create a branch named changeMicheal and in the editor you change
the content of `Michael.md`:
```bash
$ git checkout develop
$ git checkout -b changeMichael
```
Change Michael file...
```bash
$ git fetch upstream
$ git checkout develop
$ git merge upstream/develop
```
summary:
michael.md on develop:
```
# Michael
```
michael.md on changeMichael (example)
```
## Michael Evans
```
\ No newline at end of file
# Practical: Conflict resolution using kdiff3
If then there is a rebase done on develop:
```bash
$ git rebase develop
```
A conflict should emerge
* When facing the merge conflict message, use the command
```bash
$ git mergetool
```
* 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.
# Practical: Conflict resolution using kdiff3
* After resolving the conflicts, continue in your terminal
```bash
$ git rebase --continue
```
* Then check the status:
```bash
$ 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
# Getting Started
Fork and clone the tutorial repository
```bash
$ git clone ssh://git@git-r3lab-server.uni.lu:8022/<yourName>/presentations-internal.git
```
Add a remote upstream
```bash
$ git remote add upstream ssh://git@git-r3lab-server.uni.lu:8022/R3/school/advanced-git/presentations-internal.git
```
Go to the develop branch
```bash
$ git checkout develop
```
And create your own branch using the `-b` flag
```bash
$ git checkout -b myNameBranch
```
\ No newline at end of file
# Theory: Amending with Git Rebase
* The same operations can be made with `git rebase -i`
* The flag HEAD~X will let you amend the X previous commits instead of just the last one
* In the Interactive rebase menu, be sure to select the `edit` option.
\ No newline at end of file
# Practical: Amending with Git Rebase
```bash
$ git rebase -i HEAD~3
```
\ No newline at end of file
2019/2019-09-09_testCourseAdv/slides/img/afterRebase.png

126 KiB

2019/2019-09-09_testCourseAdv/slides/img/beforeRebase.png

102 KiB

2019/2019-09-09_testCourseAdv/slides/img/cherryPick.png

19.5 KiB

2019/2019-09-09_testCourseAdv/slides/img/favicon.ico

39.9 KiB

2019/2019-09-09_testCourseAdv/slides/img/r3-training-logo.png

32.4 KiB

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