Git y CI/CD
1.11.5kata 5 de 5

Advanced Git Tools

Rebase, cherry-pick, bisect, reflog y resolución de conflictos

El rebase (git rebase) reaplica tus commits sobre otra rama, creando un historial LINEAL en lugar de ramificado. git rebase main toma tus cambios y los reaplica uno a uno sobre main. Ventaja: historial limpio, fácil de entender. RIESGO: nunca hagas rebase en una rama compartida (otros colaboradores se confunden). Regla de oro: rebase localmente ANTES de pushear; merge después de que otros usan la rama.

El cherry-pick (git cherry-pick <commit>) copia un commit específico a la rama actual. Útil para portar un bugfix de una rama a otra sin mergear todo. Ejemplo: arreglaste un bug crítico en feature/X, pero necesitas que esté en main YA — en lugar de mergear feature/X completo (quizá tenga cambios inestables), simplemente cherry-pickeas el commit del bugfix. El commit se aplica de nuevo, creando un commit distinto (diferente hash).

El bisect (git bisect) es búsqueda binaria O(log n) para encontrar qué commit introdujo un bug. En lugar de revisar commits uno por uno, le dices a Git 'este commit es bueno, ese commit es malo' y git divide el rango a la mitad, reduciendo la búsqueda exponencialmente. El reflog (git reflog) es un historial de dónde ha estado HEAD — si accidentalmente borras una rama o haces un reset, reflog te permite recuperar commits 'perdidos'.

structure.txt
# === REBASE: linear history ===
git checkout feature/my-branch
git rebase main  # reaplica mis commits sobre main
# Ahora mi rama está 'adelante' de main de forma lineal

# Si hay conflictos:
git rebase --continue  # after resolving
git rebase --abort  # if you change your mind

# === CHERRY-PICK: copiar commit específico ===
git log feature/bugfix  # encontrar hash del commit
git checkout main
git cherry-pick <commit-hash>  # copia ese commit a main
# Resultado: el commit se aplica de nuevo, nuevo hash

# === BISECT: búsqueda binaria O(log n) ===
git bisect start
git bisect bad HEAD  # commit actual es 'malo' (tiene bug)
git bisect good v1.0  # commit antiguo es 'bueno' (sin bug)
# Git ahora salta a un commit en el medio
# Prueba si tiene bug
git bisect bad  # if bug exists here
# Continúa hasta encontrar el culpable exacto
git bisect reset  # salir del modo bisect

# === REFLOG: recuperar commits perdidos ===
git reflog  # historial de movimientos de HEAD
git checkout <hash>  # recuperar un commit 'perdido'

Debugging lab

Detecta y corrige el error en el código.

0/3 tests passing0%
  1. 01

    # Rebase on shared branch git rebase origin/main # en una rama que otros usan

  2. 02

    # Cherry-pick y luego mergear la rama completa

  3. 03

    # Debugging: qué commit rompió la build en el último mes?