Commit c9f3ebaa authored by JackV's avatar JackV
Browse files

2021 edition

parent ad8aadc2
Pipeline #715 passed with stage
in 1 minute and 29 seconds
......@@ -103,10 +103,10 @@
<section data-external-replace="./slides/intro.html"></section>
<section data-charset="utf-8"
data-markdown="./slides/content.md"
data-separator="^\r?\n---\r?\n$"
data-separator="^\r?\n----\r?\n$"
data-separator-notes="^Notes:"
data-separator-vertical="^\r?\n----\r?\n$">
data-separator-vertical="^\r?\n---\r?\n$">
</section>
<section data-external-replace="./slides/outro.html"></section>
</div>
</div>
\ No newline at end of file
</div>
# Intro e outro dentro l'HTML
## Git Advanced
### What we'll talk about:
Il markdown contiene solo il contenuto.
* Using git repos in a git repo: **submodule**
* Extracting commits from other branches: **cherry-pick**
* Storing changes for later use: **stash**
* Moving a branch 'ahead': **rebase**
* Finding out who made a mistake: **blame**
Di base si possono fare le slide anche in HTML se si vogliono animazioni buffe.
----
# Manage Dependencies
## Submodule
![](assets/yo-dawg-submodule.jpg)
---
## Submodule: When do I need it?
- I want to manage the dependecies of my project in a separate repository. <!-- .element: class="fragment" -->
- I want to add optional modules only if I need them. <!-- .element: class="fragment" -->
---
## Submodule: What cat it do?
A submodule will appear as a subdirectory of our own repository. <!-- .element: class="fragment" -->
Cloning a repository that contains a submodule will not clone it. <!-- .element: class="fragment" -->
---
## Submodule: What it can do?
Once created the sumodule will point always to the same commit. <!-- .element: class="fragment" -->
Every edits we could make inside our submodule will not be pushed upstream. <!-- .element: class="fragment" -->
---
## Submodule: Syntax
#### Add submodule
```bash
git submodule add [-b branch_name] repository submodule_directory
```
#### Pull the files insidea submodule
```bash
git submodule update --init --recursive submodule_directory
```
----
# Moving changes
## Cherry Pick and Stash
![](assets/one-simply-cherry-pick.jpg)
---
## Git Cherry Pick: When do I need it?
<div>
<!-- .element: class="fragment" -->
I need it when I want to import a **single** commit or **a range** of commits from another branch.
</div>
---
## Git Cherry Pick: What can it do?
<div>
<!-- .element: class="fragment" -->
Using **cherry pick**, git will perform a "rebase" (we will see later).
</div>
<div>
<!-- .element: class="fragment" -->
**N.B.** We still need to resolve every conflicts (if needed).
</div>
---
## Git Cherry Pick: Syntax
#### Take a single commit and apply on current branch
```bash
git cherry-pick <commit hash> # single commit form
git cherry-pick <hash start>..<hash end> # commit range form
```
----
## Git Stash
---
## Git Stash: When do I need it?
- I want to change branch but I'm not ready to add my current changes.
- I realized that I have no use for my new edits now, but I will need them later in the future.
- I want to **git pull** but someone else pushed changes on files that I've edited.
---
## Git Stash: How does it work?
Git stash will save by default all tracked files (also untracked with the -u option)
and leave the working tree clean.
---
## Git Stash: Syntax
#### Add current changes to stash
```bash
git stash # shortcut command
git stash push [-m "message"] # extended command
```
#### List all stash saved
```bash
git stash list
```
#### Put saved changes on top of the current working tree
```bash
git stash pop # pop the last stashed changes
git stash pop stash@{0} # same as above
git stash pop stash@{1} # pop the second-last stashed changes
git stash pop stash@{n} # and so on
```
----
# Applying new changes to an old branch
## Rebase
---
Typical situation:
1. branch B is created from branch A (eg. master)
2. some commits are made to branch B
3. some commits are made to branch A
We would like to have branch B as if we
started branching from branch A in (3)
This operation is called __rebasing__
---
### We have
![](assets/rebase-before.png)
### And we want
![](assets/rebase-after.png)
---
## Rebase on branches
Rebase, in its simplest form does the following:
1. given a branch, find at which commit history has diverged
2. compute the diff for each commit past the split
3. reapply each diff onto the current branch (conflicts apply)
4. for each new diff applied make a new commit with the original message
5. once all the commits are applied, delete the original branch
---
## How to rebase
```bash
git checkout <branch B name>
git rebase <branch A name>
```
----
# Who did this?!
## Blame
![](assets/monkey-blame.png)
---
## Git Blame: When do I need it?
I want to find who modified a file or a line. <!-- .element: class="fragment" -->
I want to find in which commit someone wrote a specific line. <!-- .element: class="fragment" -->
---
## Git Blame: What can it do?
Git blame shows all lines in a file decorated with who modified that line and with which commit. <!-- .element: class="fragment" -->
---
## Git Blame: Syntax
#### Get who wrote which line
```bash
git blame file
```
#### Same, but only for lines 13,15 and 16
```bash
git blame -L 13,15,16 file
```
----
## Ok, neat, but...
What should I use to find a bug if I don't know which lines caused it? <!-- .element: class="fragment" -->
## Git Bisect <!-- .element: class="fragment" -->
----
This is a long dash -- made of two little dashes (`--`).
## Disaster Recovery
### What we'll talk about:
* Changing past git commits - **amend** and **reset**
* Rewriting git history - **i**nteractive **rebase**
* Recovering 'deleted' files - **remote branches** and **reflog**
### tl;dr
<img src="assets/doctor.png" style="max-height: 40%" />
This dash is even longer --- and it is made of three little dashes (`---`).
---
"Quoting" is fun and easy. `"`Plain quoting`"` is ugly.
## Warning
All the commands in this presentation modify the git
history in one way or another, this can lead to
problems on shared projects and/or data loss.
----
# Heading level 1
## amending commits
## Heading level 2
---
### Heading level 3
How many times happened that you `git commit`ed and then realized that:
* There were files to include
* You made a typo in your code
* You broke your tests
#### Heading level 4
**` git commit --amend `** is the perfect tool for these situations
There are **no** more heading levels.
---
```bash
# Add the missing files
$ git add missing.txt
# and then add it in the current commit
$ git commit --amend
```
----
<x-section-title>This is a section title</x-section-title>
## Undoing a lot of commits at once
---
If you want the section title in the top-right cornet
you can add **&lt;x-section-title&gt;title&lt;/x-section-title&gt;** in the slide
### git reset
`git reset` allows us to move **HEAD** (our current branch) to **`<commit>`**
There are 3 modes:
* `--soft`: changed files return to the staging area
* `--mixed` (default): changed files become un-staged
* `--hard`: changes are deleted, working tree will be clean
----
```python
import sys
## Interactive Rebase
---
## Interactive Rebase
Rebase can also be used to touch-up a commit history
```bash
git rebase -i <start commit>..<end commit>
git rebase -i <start commit> # end commit is HEAD
```
---
Once run a file will be opened with __$EDITOR__ (e.g. vim)
Possible operations:
* reword: change the commit message
* edit: change the file just before they were committed
* squash/fixup: apply the changes in this commit to the previous commit
* drop: delete the commit entirely
----
## Remote Branches
---
x = 1 + 2
Sometimes we mess up the commit history and want to go back to a "safe" state
if x > 2:
pass
Git stores special branches that point to the remote's branches
try:
with open('/dev/null') as f:
pass
except IOError:
raise Exception('Error!')
finally:
sys.exit()
---
### Example
We have remote `origin` (the default) and branch `master`, we
want to reset our local `master` branch to the remote one
```bash
git fetch # Update the remote repo in case there are changes
git checkout origin/master
# Now we are where we where the remote is
git checkout -B master
# We assign the current commit to our local master branch
```
----
- Do you remember bullet list?
```python
bullet_list = ["Do you remember bullet list?"]
```
- You can also allign code to bullet lists!
```python
bullet_list.append("You can also allign code to bullet lists!")
```
- It's not too hard!
```python
if not hard:
bullet_list.append("It's not too hard!")
```
\ No newline at end of file
## Reflog
### How to find lost commit shas
---
Git stores the commit sha changes in a log
This can be accessed with:
```bash
git reflog
```
---
In the reflog there are references to all the commits made, even
the ones that are unreachable and the intermediate commits of a rebase
----
# Questions?
----
# Big Thanks to:
- [__Emanuele Santoro__](http://santoro.tk)
- __Luca Fusé__
For their fantastic slides on advanced git topics of the previous years
<section class="intro">
<h1>Corsi Punto Croce 2018</h1>
<h2>Come fare gli orli</h2>
<h1>Advanced Git & Disaster Recovery</h1>
<img src="./poul/img/logo-text-white.svg"/>
<p>Autore &lt;email@email.com&gt;</p>
</section>
\ No newline at end of file
<p>Giacomo Vercesi &lt;1vercesig@gmail.com&gt;</p>
</section>
......@@ -7,5 +7,5 @@
<img class="cc" src="./poul/img/creativecommons-by-nc-sa.svg"/>
<p>Autore &lt;email@email.com&gt;</p>
</section>
\ No newline at end of file
<p>Giacomo Vercesi &lt;1vercesig@gmail.com&gt;</p>
</section>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment