Git : l'historique d'un projet (école d'ingénieur) · Chapitre 4 · Application directe du cours
Changer de branche avec du travail en cours
Les branches · niveau 2
Énoncé
Ada est sur main, dans le dépôt de l'exercice 4.3, avec du travail en cours ; git diff --stat main correctif compare les deux branches :
$ git status --short
M a.txt
M b.txt
?? note.txt
$ git diff --stat main correctif
b.txt | 1 +
1 file changed, 1 insertion(+)
git switch correctifva-t-il réussir ?- Ada tient à sa modification de
a.txtet ànote.txt, pas à celle deb.txt. Passer surcorrectifsans rien commiter.
Corrigé
- Non :
b.txtdiffère entre les deux branches et est modifié localement ; le changement de branche l'écraserait.a.txt, identique sur les deux branches, etnote.txt, non suivi, ne gênent pas. - On abandonne la modification de
b.txt, puis on change de branche ; les deux autres suivent (ex09-en-cours.sh) :
$ git switch correctif
error: Your local changes to the following files would be overwritten by checkout:
b.txt
Please commit your changes or stash them before you switch branches.
Aborting
$ git restore b.txt
$ git switch correctif
M a.txt
Switched to branch 'correctif'
$ git status --short
M a.txt
?? note.txtExercices semblables
- Prévoir un graphe corrigé
- Lire un graphe corrigé
- Résoudre un conflit corrigé
- Un commit sur la mauvaise branche corrigé
- Supprimer des branches corrigé