Von Gast (nicht überprüft) , 29 April 2026

Was Sie erreichen werden

Sie werden einen Feature-Branch mit unordentlichen Work-in-Progress-Commits nehmen und ihn in eine saubere atomare Serie umschreiben.

Einen Sandbox einrichten

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"

Schritt 1: uberprufen

git log --oneline

Schritt 2: interaktiver Rebase

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

Schritt 3: das Skript umschreiben

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

Schritt 4: jeden Commit umbenennen

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

Schritt 5: verifizieren

git log --oneline
git log

Schritt 6: Push

git push --force-with-lease

Der Fixup-Workflow wahrend der Entwicklung

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

Einen zu grossen Commit aufteilen

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

Fallstricke

  • Niemals einen Branch rebasen, auf dem andere Arbeit basieren.
  • Immer --force-with-lease.
  • Nach dem Rebase testen.

Wiederherstellung

git reflog
git reset --hard ORIG_HEAD