Misión: crear un proyecto, hacer 3 commits y corregir el último.
mkdir test-git && cd test-git && git init
# 3 commits
echo "print('v1')" > app.py && git add . && git commit -m "Version 1"
echo "print('v2')" > app.py && git add . && git commit -m "Version 2"
echo "print('v3 with bug')" > app.py && git add . && git commit -m "Version 3"
# Corregir el último commit
echo "print('v3 fixed')" > app.py && git add . && git commit --amend -m "Version 3 - Fixed"Comprobación: git log --oneline → 3 commits; el último dice "Fixed"
Misión: 2 features en paralelo, fusionar con limpieza.
# Base
echo "print('main')" > main.py && git add . && git commit -m "Main app"
# Feature 1
git checkout -b feature-login
echo "print('login')" > login.py && git add . && git commit -m "Add login"
# Feature 2
git checkout main && git checkout -b feature-api
echo "print('api')" > api.py && git add . && git commit -m "Add API"
# Fusionar todo en main
git checkout main
git merge feature-login
git merge feature-api
# Limpiar
git branch -d feature-login feature-apiComprobación: git log --graph --oneline → ver los merges
Misión: el mismo escenario, 2 estrategias distintas.
mkdir test-merge && cd test-merge && git init
echo "print('base')" > app.py && git add . && git commit -m "Base"
# Feature branch
git checkout -b feature
echo "print('feature')" > feature.py && git add . && git commit -m "Add feature"
# Main avanza
git checkout main
echo "print('base v2')" > app.py && git add . && git commit -m "Update base"
# Merge
git merge feature
git log --graph --oneline # Ver el historial con mergemkdir test-rebase && cd test-rebase && git init
echo "print('base')" > app.py && git add . && git commit -m "Base"
git checkout -b feature
echo "print('feature')" > feature.py && git add . && git commit -m "Add feature"
git checkout main
echo "print('base v2')" > app.py && git add . && git commit -m "Update base"
# Rebase
git checkout feature && git rebase main
git checkout main && git merge feature
git log --oneline # Historial linealPregunta: ¿qué diferencia ves en git log?
Misión: hacer malabares con varias tareas.
mkdir test-stash && cd test-stash && git init
echo "print('v1')" > app.py && git add . && git commit -m "Version 1"
# Empiezas a programar
echo "print('work in progress')" >> app.py
# ¡URGENCIA! Tienes que cambiar de rama
git stash # Guardar
git checkout -b hotfix
echo "print('URGENT FIX')" > fix.py && git add . && git commit -m "Critical fix"
# Cherry-pick del arreglo hacia main
git checkout main
git cherry-pick <hash-du-fix>
# Volver a tu trabajo
git stash pop
echo "print('feature complete')" >> app.py && git add . && git commit -m "Feature done"Reto: ¿el arreglo urgente está en main Y en hotfix?
Misión: simular una urgencia con reset.
mkdir test-urgence && cd test-urgence && git init
# Varios commits
echo "print('v1')" > app.py && git add . && git commit -m "Version 1"
echo "print('v2')" > app.py && git add . && git commit -m "Version 2"
echo "print('v3')" > app.py && git add . && git commit -m "Version 3"
echo "print('v4 BROKEN')" > app.py && git add . && git commit -m "Version 4 - Bug!"
# ¡Oh no! v4 lo rompe todo en producción
git log --oneline # Anotar el hash de v3
# Solución 1: reset hard (destructivo)
git reset --hard <hash-v3> # Vuelta a v3, v4 desaparece
git log --oneline # Solo 3 commits
# Solución 2: revert (seguro)
# Volver a poner v4 primero
git reset --hard <hash-v4> # Volver a v4
git revert HEAD # Crear un commit que anula v4
git log --oneline # 5 commits: v1,v2,v3,v4,revert-v4Lección: revert = seguro en producción; reset = OK en local
¿Puedes hacer todo esto en 15 minutos?
Si sí → ¡dominas Git!