Git Advanced Workflows: Rebase, Cherry-pick e Historia Interactiva
Git Advanced Workflows: Rebase, Cherry-pick e Historia Interactiva
Basic Git (add, commit, push) te inicia. Advanced Git te hace un profesional. Dominemos las técnicas que separan a los principiantes de los expertos. ## Why Advanced Git Matters
Los desarrolladores profesionales necesitan:
- 📝 Clean commit history
- Estrategias flexibles de ramificación
- Capacidad para corregir errores
- Colaboración del equipo Smooth
Git Rebase: Reescribir Historia
Merge vs Rebase
Merge
main: A---B---C---D
\ \
feature: E---F---G---M
Rebase:
main: A---B---C---D
\
feature: E'--F'--G'
Rebase básico
Loading code...
Qué pasa
- Git encuentra un ancestro común
- Guarda tus compromisos (E, F, G)
- Aplica los compromisos de main
- Replays your commits on top ## Manejo de conflictos _CODE_BLOCK_3 ## Rebase Interactive: Clean Up Commits ### Squash Commits _CODE_BLOCK_4 ### Reorder Commits ```bash git rebase -i HEAD~4
Original order:
pick abc1234 Add feature A pick def5678 Add feature B pick ghi9012 Fix bug in A pick jkl3456 Add tests
Reorder:
pick abc1234 Add feature A
pick ghi9012 Fix bug in A
pick def5678 Add feature B
pick jkl3456 Add tests
### Editar mensaje de compromisobash
git rebase -i HEAD~2
Change:
pick abc1234 WIP: Add feature pick def5678 Tests
To:
reword abc1234 WIP: Add feature pick def5678 Tests
Save - new editor opens for message
_ ## Dividir un compromiso bash
git rebase -i HEAD~1
Change:
pick abc1234 Add user and order models
To:
edit abc1234 Add user and order models
Git pauses, now:
git reset HEAD^
git add user.model.js
git commit -m "Add user model"
git add order.model.js
git commit -m "Add order model"
git rebase --continue
##### Cherry-pick: Seleccione Commits Específicos ### Basic Cherry-pick __CODE_BLOCK_8_ #### Rango Cherry-pickbash
Pick multiple commits
git cherry-pick abc1234..ghi9012
Pick commits (excluding first)
git cherry-pick abc1234^..ghi9012
# Cerebro sin compromiso bash
Apply changes without committing
git cherry-pick -n def5678
Make changes
git add .
git commit -m "Custom message"
### Git Reflog: Recover Lost Commits __CODE_BLOCK_11_ ## Git Stash: Save Work in Progress ## Basic Stashbash
Save current changes
git stash
Save with message
git stash save "WIP: User authentication"
List stashes
git stash list
Apply latest stash
git stash pop
Apply specific stash
git stash apply stash@{2}
## Stash Specific Filesbash
Stash only staged files
git stash --staged
Stash including untracked files
git stash -u
Stash specific files
git stash push -m "Stash config" config.js
#### Create Branch from Stash __CODE_BLOCK_14_ ## Git Bisect: Encontrar errores con búsqueda binaria __CODE_BLOCK_15_ ## Automated Bisectbash
Automate with test script
git bisect start HEAD abc1234 git bisect run npm test
Git automatically finds bad commit
## Git Worktree: Múltiples directorios de trabajo __CODE_BLOCK_17_ ## Advanced Reset Strategies ## Soft Reset (Keep Changes Staged) __CODE_BLOCK_18_ ## Mixed Reset (Default - Keep Changes Unstaged) __CODE_BLOCK_19_ ### Hard Reset (Discard Changes) __CODE_BLOCK_20_ ## Git Hooks: Automate Workflows ## Pre-commit Hook __CODE_BLOCK_21_ ### Commit Message Hook __CODE_BLOCK_22_ ## Git Aliases: Ahorra tiempobash
Add to ~/.gitconfig
[alias]
Shortcuts
co = checkout br = branch ci = commit st = status
Log with graph
lg = log --graph --oneline --all --decorate
Undo last commit
undo = reset --soft HEAD~1
Amend without editing message
amend = commit --amend --no-edit
Show branches sorted by last commit
recent = branch --sort=-committerdate
Clean branches (merged to main)
cleanup = !git branch --merged main | grep -v "main" | xargs git branch -d
## Workflow Strategies ## Git Flow __CODE_BLOCK_24_ _____________ ## Trunk-Based Development
main (always deployable)
↓
short-lived feature branches (< 1 day)
Loading code...