Git : l'historique d'un projet (école d'ingénieur) · Chapitre 8 · Application directe du cours
Écraser un conflit, puis le retrouver
Projet : la Librairie en équipe · niveau 2
Énoncé
Cet exercice prolonge l'exercice 5.9. Sur main, le prix de L'Étranger est passé de 7.50 à 6.90 ; sur la branche roman, Germinal a été ajouté sur la ligne suivante. Depuis roman, on rebase (exercices/ex07-ours.sh) :
$ git rebase -q main
Auto-merging livres.csv
CONFLICT (content): Merge conflict in livres.csv
error: could not apply e168799... feat: ajoute Germinal (branche roman)
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply e168799... # feat: ajoute Germinal (branche roman)
$ git diff
diff --cc livres.csv
index 44edd29,748754d..0000000
--- a/livres.csv
+++ b/livres.csv
@@@ -1,2 -1,3 +1,7 @@@
isbn,titre,auteur,prix
++<<<<<<< HEAD
+9782070360024,L'Étranger,A. Camus,6.90
++=======
+ 9782070360024,L'Étranger,A. Camus,7.50
+ 9782253004226,Germinal,É. Zola,8.90
++>>>>>>> e168799 (feat: ajoute Germinal (branche roman))
- Prévoir les deux dernières lignes de
livres.csvaprèsgit checkout --ours livres.csv, puis aprèsgit checkout --theirs livres.csv. - Comment retrouver ensuite le fichier avec ses marqueurs de conflit ?
- Comment abandonner le rebase, et dans quel état revient-on ?
Corrigé
Pendant un rebase, HEAD est le commit sur lequel Git rejoue la branche, donc main : --ours donne la version de main (le nouveau prix, sans Germinal), et --theirs celle du commit rejoué (l'ancien prix et Germinal). git checkout --merge recrée les marqueurs, cette fois étiquetés ours et theirs ; et git rebase --abort ramène la branche à son état d'avant, commit d'origine compris :
$ git checkout --ours livres.csv
Updated 1 path from the index
$ tail -n 2 livres.csv
isbn,titre,auteur,prix
9782070360024,L'Étranger,A. Camus,6.90
$ git checkout --theirs livres.csv
Updated 1 path from the index
$ tail -n 2 livres.csv
9782070360024,L'Étranger,A. Camus,7.50
9782253004226,Germinal,É. Zola,8.90
$ git checkout --merge livres.csv
Recreated 1 merge conflict
$ cat livres.csv
isbn,titre,auteur,prix
<<<<<<< ours
9782070360024,L'Étranger,A. Camus,6.90
=======
9782070360024,L'Étranger,A. Camus,7.50
9782253004226,Germinal,É. Zola,8.90
>>>>>>> theirs
$ git rebase --abort
$ git log --oneline -1
e168799 (HEAD -> roman) feat: ajoute Germinal (branche roman)
Aucune des deux versions n'est la bonne : la résolution garde le prix de main et la ligne de Germinal, comme à la section 8.4. --ours et --theirs servent quand un côté doit l'emporter en entier (un fichier généré, par exemple).
Exercices semblables
- Combien d'essais corrigé
- Un conflit pendant une fusion corrigé
- Fusionner ou rebaser corrigé
- Les tests avant chaque push corrigé
- La version suivante corrigé