Skip to content
Snippets Groups Projects
Verified Commit 75163cf0 authored by Laurent Heirendt's avatar Laurent Heirendt :airplane:
Browse files

adapt the slides for cherr-picking

parent c3ce4d6a
No related branches found
No related tags found
No related merge requests found
# Theory: Git Cherry-picking
# Cherry-picking
* It enables the user to pick specific commits from a list of commits.
* 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.
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 style="top: 8em; left: 25%; position: absolute;">
<img src="slides/img/cherryPick.png" height=500px>
</div>
# Practical: Git Cherry-picking
# Example (1)
* In your branch, create and commit a reference file
* In your branch `myBranch`, create and commit a reference file `references.md`:
```bash
$ echo "This is the start of a commit chain" > reference.txt
$ git add reference.txt
$ git commit origin myBranch
$ git checkout myBranch
$ echo "# References" > references.md
$ # add and commit the file references.md
```
* Create and commit two files in the develop branch
* 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
$ echo "# Venue details" > location.md
$ # add and commit the file location.md
$ echo "# Speakers" > speakers.md
$ # add and commit the file speakers.md
```
# Practical: Git Cherry-picking
# Example (2)
* Check the commit reference of the two commits in develop
* Chose the commit to keep and add it to your branch
* Check the `log` and note down the `SHA1` of the commits you want to cherry-pick. Then:
```bash
$ git checkout myBranch
$ git cherry-pick <commit reference>
$ git cherry-pick <SHA1>
```
* Check the log again and see if the changes were applied correctly
```bash
$ git show <newSHA1>
```
* Repeat for the second commit
* push the changes to the develop branch
* Push the changes to `myBranch`
```bash
$ git push origin myBranch -f
$ git push origin myBranch
```
* The `-f` flag is used to force push into develop
\ No newline at end of file
* Note that the `-f` flag is not needed to force push (no history has been rewritten)
\ No newline at end of file
2019/2019-09-24_advancedGitTraining/slides/img/cherryPick.png

19.5 KiB | W: | H:

2019/2019-09-24_advancedGitTraining/slides/img/cherryPick.png

31.1 KiB | W: | H:

2019/2019-09-24_advancedGitTraining/slides/img/cherryPick.png
2019/2019-09-24_advancedGitTraining/slides/img/cherryPick.png
2019/2019-09-24_advancedGitTraining/slides/img/cherryPick.png
2019/2019-09-24_advancedGitTraining/slides/img/cherryPick.png
  • 2-up
  • Swipe
  • Onion skin
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