## Advanced Exercises
## ------------------
##   * The following exercises should be run on the repo
## resulting from single_local
##   * The solutions are provided as they introduce some new commands.
## However, feel free to try without the solutions first.
## (use `grep '##' advanced.txt to get a file without solutions)
##   * Make sure you really understand what happens with your files
## but also in the repository in each of the steps
## `...` and `<somestring>` are placeholders you will need to replace
##    with correct values

## 1) selecting commits
##    - Create a new branch `minimal` containing only `add` and `sub`
##    (without multiplication but with the renamed sub)
git switch -c minimal <last commit before multiplication>
git cherry-pick <fix substract -> sub>

## 2) resolving confilcts when cherry-picking
##    - add logging to `minimal`
git cherry-pick <logging>
# read output carefully, incl. output of `git status`
vim simple_math.py
# fix conflict
git add simple_math.py
git cherry-pick --continue

## 3) work with a devel branch
##    - create a new branch devel from master
git switch -c devel master
##    - add a pow function in devel
vim simple_math.py
git commit simple_math.py -m "add pow"
##    - change something on the master branch (e.g. add a file demo.py)
git switch master
vim demo.py
git add demo.py
git commit -m "add usage demo"
##    - add a sqrt-function in devel
git switch devel
vim simple_math.py
git commit simple_math.py -m "add sqrt"
##    - inspect the state
git status
git log --all --graph
##    - merge devel into master
git switch master
git merge devel
git log --all --graph
##    - move devel to the state of master (including the missing commit)
git switch devel
git rebase master
git log --all --graph
## create new commits on devel and master, then first rebase then merge

## 4) cloning locally
##   - make sure you have master checked out
git switch master
##   - move the `.git` directory out of the repo, rename it to e.g. `bare_exp.git`
cd <path-outside-repo>
mv <path-of-repo>/.git bare_exp.git
##   - edit the config file and set `bare = true`
vim bare_demo.git/config
##   - clone from the bare repo
cd <new-path>
git clone <path-outside-repo>/bare_exp.git experiments
##   - play around in experiments, try push and pull

## 5) Play with `reset`, `restore` and `git commit --amend`
##   - create a new commit
vim simple_math.py
git commit simple_math.py -m ...
##   - look at the log and get the hash for the commit before last
git log
##   - reset the last commit using `--hard`
git reset --hard <commit before last>
##   - redo the commit
vim simple_math.py
git commit simple_math.py -m ...
##   - reset the last commit using `--soft`
git reset --soft <commit before last>
##   - restore the file
git restore --staged simple_math.py
##   - change the file some more the recommit
vim simple_math.py
git commit simple_math.py -m ...
##   - change the file again, add it and then run `git commit --amend`
vim simple_math.py
git add simple_math.py
git commit --amend
## repeat this with setup where there is a remote repo
## or even two both working on the same files
