Da Anonimo (non verificato) , 29 Aprile 2026

Cosa otterrai

Prenderai un branch di feature con commit work-in-progress disordinati e lo riscriverai in una serie pulita e atomica pronta per la review.

Configurare un sandbox

mkdir cleanup-tutorial && cd cleanup-tutorial
git init
echo "main" > app.txt && git add . && git commit -m "Initial"
git checkout -b feature
echo "1" > one.txt && git add . && git commit -m "wip"
echo "2" > two.txt && git add . && git commit -m "more wip"
echo "3" > three.txt && git add . && git commit -m "fix"
echo "fixed" >> one.txt && git commit -am "actually fix one"
echo "lint" >> three.txt && git commit -am "lint"

Passo 1: revisione

git log --oneline

Passo 2: rebase interattivo

git rebase -i main
pick aaa1111 wip
pick bbb2222 more wip
pick ccc3333 fix
pick ddd4444 actually fix one
pick eee5555 lint

Passo 3: riscrivere lo script

pick aaa1111 wip
fixup ddd4444 actually fix one
pick bbb2222 more wip
pick ccc3333 fix
fixup eee5555 lint

Passo 4: rinominare ogni commit

git rebase -i main
reword AAA111 wip
reword BBB222 more wip
reword CCC333 fix

Passo 5: verificare

git log --oneline
git log

Passo 6: push

git push --force-with-lease

Il workflow fixup durante lo sviluppo

git commit --fixup <target-sha>
git rebase -i --autosquash main

Dividere un commit troppo grande

git rebase -i main
git reset HEAD^
git add -p
git commit -m "First atomic piece"
git add -p
git commit -m "Second atomic piece"
git rebase --continue

Insidie

  • Mai fare rebase di un branch su cui altri hanno basato lavoro.
  • Sempre --force-with-lease.
  • Testare dopo il rebase.

Recupero

git reflog
git reset --hard ORIG_HEAD