Interaktives Rebase und Ändern von Commits
Lernen Sie, mit `git rebase -i` die Historie für übersichtlichere Commits umzuschreiben und mit `git commit --amend` den letzten Commit zu ändern.
Interaktives Rebase und Ändern von Commits ist eine kostenlose Git Advanced: Monorepo, Submodules & Workflows-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Git Advanced: Monorepo, Submodules & Workflows-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Git Advanced: Monorepo, Submodules & Workflows-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Clean Up Your Git History
Git history gets messy — a forgotten file, a typo'd message, ten tiny commits that should be one. Git lets you rewrite history to clean it up.
Amending Your Last Commit
git commit --amend fixes your most recent commit: change the message, add forgotten files, or tweak content. It replaces the last commit with a tidier one.
Amending a Commit Example
Forgot a file right after committing? Stage it, then git commit --amend folds it into the last commit. Here's the flow.
# 1. Make some changes and commit
echo "Initial content" > file1.txt
git add file1.txt
git commit -m "Add file1"
# 2. Realize you forgot file2.txt
echo "More content" > file2.txt
git add file2.txt
# 3. Amend the last commit to include file2.txt
git commit --amend --no-editIntroducing Interactive Rebase
Need to fix commits further back, not just the last one? Interactive rebase (git rebase -i) is a full editor for a series of commits.
Getting Started with Rebase -i
Start an interactive rebase by naming a commit before your target range. To edit the last three commits, use HEAD~3.
git rebase -i HEAD~3Rebase Commands: Pick, Reword, Squash
The rebase editor lists commits with commands you can swap: pick keeps it, reword edits the message, squash/fixup merge it up, edit pauses to amend.
Rewording a Commit Message
To change an older commit's message, switch its line from pick to reword in the editor. Git then prompts you for the new message.
# Original rebase editor content:
# pick 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docs
# Change 'pick' to 'reword' for the first commit:
# reword 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docsSquashing Commits Together
Got several small commits that belong together? squash merges them into one meaningful commit — change the lines below pick to squash.
# Original commits:
# pick abc1234 Add user registration form
# pick def5678 Add validation for email field
# pick ghi9012 Fix styling on form
# To squash the last two into the first:
# pick abc1234 Add user registration form
# squash def5678 Add validation for email field
# squash ghi9012 Fix styling on formEditing an Older Commit
The edit command pauses the rebase at a specific commit. Make changes, git add, git commit --amend, then git rebase --continue.
When to Be Careful with Rewriting
Rewriting changes commit IDs — safe for local-only commits. Never rewrite history that's already pushed and shared; it wrecks your collaborators' work.
Quick Check: History Rewriting
You've made a commit with the message "Fix bug". You then realize you forgot to include one small file in that commit. What is the most appropriate Git command to fix this, assuming you haven't pushed the commit yet?
Recap: Cleaner Commits
Recap: git commit --amend fixes the last commit, while git rebase -i rewrites a series — reword, squash, fixup, or edit. Just be careful on shared branches.
Häufig gestellte Fragen
Ist die Lektion „Interaktives Rebase und Ändern von Commits“ kostenlos?
Ja — der vollständige Text von „Interaktives Rebase und Ändern von Commits“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Git Advanced: Monorepo, Submodules & Workflows-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Git Advanced: Monorepo, Submodules & Workflows-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Interaktives Rebase und Ändern von Commits“?
Lernen Sie, mit `git rebase -i` die Historie für übersichtlichere Commits umzuschreiben und mit `git commit --amend` den letzten Commit zu ändern. Du übst Git Advanced: Monorepo, Submodules & Workflows mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Git Advanced: Monorepo, Submodules & Workflows zu starten?
Keine Vorkenntnisse erforderlich. Git Advanced: Monorepo, Submodules & Workflows auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Interaktives Rebase und Ändern von Commits“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Git Advanced: Monorepo, Submodules & Workflows-Lektion Code schreiben und ausführen?
Ja. Jede Git Advanced: Monorepo, Submodules & Workflows-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Interaktives Rebase und Ändern von Commits
- Änderungen stashen und cherry-picken
- Reflog zur Wiederherstellung
- Bisect: Fehlerhafte Commits aufspüren