git rebase
git
Syntaxe
git rebase [-i] [--onto <base>] <upstream>Rejoue vos commits sur une nouvelle base ; les hachages changent, donc ne rebasez jamais une branche déjà récupérée par d'autres : utilisez merge.
Options courantes
| Option | Signification |
|---|---|
| -i | interactive: reorder, squash, reword, drop commits |
| --onto <base> | move the range onto a different base |
| --continue | carry on after fixing a conflict |
| --abort | put the branch back exactly as it was |
| --skip | drop the commit that will not apply |
| --autostash | stash uncommitted work and put it back afterwards |
| --autosquash | apply fixup!/squash! commits automatically |
Exemples
git rebase mainreplays your commits on top of main, giving them new hashes
git rebase -i HEAD~3squash or reword the last three commits
git rebase --abortcancel a rebase and return to the original branch
Ce qui embrouille, c’est qu’annuler a plusieurs formes : déplacer là où pointe une branche n’est pas ajouter un commit qui l’inverse.
Comment lire
- Les crochets [ ] marquent une partie facultative.
- Les points de suspension … signifient qu’on peut en mettre plusieurs.
- Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.
Questions fréquentes
Q. Que fait git rebase ?
Rejoue vos commits sur une nouvelle base ; les hachages changent, donc ne rebasez jamais une branche déjà récupérée par d'autres : utilisez merge.
Q. Comment l’écrire ?
git rebase [-i] [--onto <base>] <upstream> — les crochets marquent ce qui est facultatif.
Q. Combien d’options valent la peine ?
Il y en a 7 ici ; la liste complète est dans man git. Cette commande relève de git.
Commandes liées
page man: man git-rebase