Painlessly Improve Your Git History
Maëlle Salmon
Git installation, basic usage.
saperlipopette installation https://docs.ropensci.org/saperlipopette/
Two sticky notes. “I’m done!”: pink or green. “I need help!”: yellow.
Any question?
In your usual Git environment.
Informal poll.
In temporary folders created by {saperlipopette}.
So we won’t break any important project.
A tool to use Git
An R package to create exercises in distinct folders.
R to create the exercise in another folder.
R in the new session to read the instructions.
Your usual tools to solve the Git problem!
Call a function from an R session.
Go to the created folder (shown in the output).
Open R in this folder, read the instructions.
Work with your Git tools or the terminal.
Close the exercise session.
You have 10 minutes to fix it!
Less work loss;
Experimentation in branches;
History to use (locally and on platforms like GitHub).
Small commits (changes) with informative messages
“Add a bunch of files before lunch 🍝”
Shows 145 files changed with 2,624 additions and 2,209 deletions.
“fix: adapt code to 0-indexing of the tool”
Shows 2 files changed with 3 additions and 2 deletions.
Oh no, that idea from 7 commits ago is bad! Should we…
Manually delete the change;
Undo (“Revert”) the commit that added the change?
This only works well if the commit is small.
.
.
.
“Add a bunch of files before exercise 💪”.
Shows 145 files changed with 2,624 additions and 2,209 deletions.
“refactor: start using YAML”
Shows 2 files changed with 3 additions and 2 deletions.
“there’s no need for everyone to see the mistakes you made along the way”
Mike McQuaid, Git in practice
5 minutes!
Another dimension to your work.
Working in branches
git commit --amendWhat is git commit --amend
5 minutes
git commit --amendhttps://happygitwithr.com/repeated-amend
First part of the work, git commit -m "feat: add cool thing"
Second part of the work, git commit --amend --no-edit
…
It’s done! git push
git commit --amendgit checkout -b 'feature-cool'
First part of the work, git commit -m "feat: add cool thing", git push
Second part of the work, git commit --amend --no-edit, git push -f
…
It’s done! git push -f
.
git reset --mixed Changes in the directory but not the Git history.
git add (--patch) Good commits, in hindsight.
git add --patch5 minutes
5 minutes
git rebase -i
Resources on git rebase
10 minutes
Either
Or
Better history, especially for
git blame
git bisect
git revert
✨ You don’t need to get it right the first time ✨
The Repeated Amend ™️
Squash and merge PRs
Start from scratch
Mix and match your commits
The terminal: it never changes, and you learn the words.
RStudio IDE
Positron IDE, GitLens extension
Other IDEs
GitHub Desktop
Practice safely with the {saperlipopette} playgrounds!
Still other exercises to try. 😉
Thank you! 💙
Thanks to the uRos team especially TA Ciprian Alexandru.
Julia Evans’ zines “Oh shit, Git!” and “How Git works”
Book Git in Practice by Mike McQuaid (reading notes)
Book Pro Git by Scott Chacon (reading notes)