0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Lección

Rebase interactivo y modificación de commits

Aprenda a reescribir el historial con `git rebase -i` para obtener commits más limpios y utilice `git commit --amend` para modificar el último commit.

Rebase interactivo y modificación de commits es una lección gratuita de Git Advanced: Monorepo, Submodules & Workflows en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Git Advanced: Monorepo, Submodules & Workflows, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Git Advanced: Monorepo, Submodules & Workflows incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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-edit

Introducing 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~3

Rebase 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 docs

Squashing 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 form

Editing 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.

Preguntas frecuentes

¿La lección «Rebase interactivo y modificación de commits» es gratis?

Sí — el texto completo de «Rebase interactivo y modificación de commits» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Git Advanced: Monorepo, Submodules & Workflows, actualiza a CoddyKit PRO. El curso de Git Advanced: Monorepo, Submodules & Workflows incluye 4 lecciones en total.

¿Qué aprenderé en «Rebase interactivo y modificación de commits»?

Aprenda a reescribir el historial con `git rebase -i` para obtener commits más limpios y utilice `git commit --amend` para modificar el último commit. Practicas Git Advanced: Monorepo, Submodules & Workflows con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Git Advanced: Monorepo, Submodules & Workflows?

No se requiere experiencia previa. Git Advanced: Monorepo, Submodules & Workflows en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.

¿Cuánto tiempo toma la lección «Rebase interactivo y modificación de commits»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Git Advanced: Monorepo, Submodules & Workflows?

Sí. Cada lección de Git Advanced: Monorepo, Submodules & Workflows incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Rebase interactivo y modificación de commits
  2. Stash y cherry-pick de cambios
  3. Reflog para recuperación
  4. Bisect: búsqueda de commits defectuosos
← Volver a Git Advanced: Monorepo, Submodules & Workflows