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

overall changes to fit partial cherry-picking and note on common commands

parent 75163cf0
No related branches found
No related tags found
No related merge requests found
......@@ -11,13 +11,6 @@
# Example (1)
* In your branch `myBranch`, create and commit a reference file `references.md`:
```bash
$ git checkout myBranch
$ echo "# References" > references.md
$ # add and commit the file references.md
```
* Create and commit two files in the `develop `branch
```bash
$ echo "# Venue details" > location.md
......@@ -35,7 +28,7 @@ $ # add and commit the file speakers.md
$ git checkout myBranch
$ git cherry-pick <SHA1>
```
* Check the log again and see if the changes were applied correctly
* Check the log again and see if the changes were applied correctly. Note the new SHA1!
```bash
$ git show <newSHA1>
```
......@@ -46,4 +39,54 @@ $ git show <newSHA1>
$ git push origin myBranch
```
* Note that the `-f` flag is not needed to force push (no history has been rewritten)
\ No newline at end of file
* Note that the `-f` flag is not needed to force push (no history has been rewritten)
# 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)
* Reset the `develop` branch:
```bash
$ git checkout develop
$ git reset HEAD~2
```
* 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"
```
# Example (2)
Cherry-pick the commit from `develop` over to `myBranch`:
```bash
$ git checkout myBranch
$ git cherry-pick -n <SHA1>
$ git status
```
Now, remove the file `location.md`:
```bash
$ git restore --staged location.md
$ rm location.md
```
Commit the changes:
```bash
$ git commit -m "add speakers file"
```
......@@ -24,3 +24,25 @@ Create your own branch `myBranch` based on the `develop` branch from `usptream`
```bash
$ git checkout -b <mybranch> upstream/develop
```
# A note on common commands:
This workshop will not cover in detail the following commands, assuming you are familiar with them:
- `git checkout`
- `git add`
- `git commit`
- `git log`
- `git show`
Feel free to ask any questions if you run into any issues!
For your reference:
```bash
$ git <command> --help
```
Replace `<command>` with the command you want help for.
Exit with `q`
# 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.
# Practical: Amending with Git Rebase
```bash
$ git rebase -i HEAD~3
```
\ No newline at end of file
......@@ -7,7 +7,6 @@
{ "filename": "revert.md" },
{ "filename": "rebase.md" },
{ "filename": "chPick.md" },
{ "filename": "headRebase.md" },
{ "filename": "merge.md" },
{ "filename": "conflict.md" },
{ "filename": "kdiff3Install.md" },
......
......@@ -102,8 +102,10 @@ $ 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, omitting the commit message of the second commit.
- 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.
......
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