Por Anónimo (no verificado) , 29 Abril 2026

Lo que lograrás

Tomarás un branch feature con commits work-in-progress desordenados ("wip", "more wip", "fix lint", "address feedback") y lo reescribirás en una serie limpia de commits atómicos lista para review.

Configurar 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"

Paso 1: revisar

git log --oneline

Paso 2: rebase interactivo

git rebase -i main

Paso 3: reescribir el script

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

Paso 4: reescribir cada commit

git rebase -i main
reword AAA111 wip
reword BBB222 more wip
reword CCC333 fix
Add file one with initial content

The first piece of the feature, providing the base data structure.

Paso 5: verificar

git log --oneline
git log

Paso 6: pushear

git push --force-with-lease

El flujo de fixup durante desarrollo

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

Dividir un commit demasiado grande

git rebase -i main
git reset HEAD^
git add -p
git commit -m "Primera pieza atómica"
git add -p
git commit -m "Segunda pieza atómica"
git rebase --continue

Trampas

  • Nunca hagas rebase de un branch en el que otros hayan basado trabajo.
  • Siempre --force-with-lease, nunca --force en branches compartidos.
  • Prueba después de rebase.

Recuperación

git reflog
git reset --hard ORIG_HEAD