Adloun

Git : l'historique d'un projet (école d'ingénieur) · Chapitre 6 · Application directe du cours

Publier malgré un refus

Les dépôts distants · niveau 2

Énoncé

Dans le clone a, on a validé « Ajoute Candide » ; entre-temps, le clone b a envoyé « Ajoute Zadig » :


$ git push
To /srv/essai.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to '/srv/essai.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Écrire les commandes qui publient « Ajoute Candide » en gardant un historique linéaire, et dessiner le graphe obtenu.

Corrigé

Pour un historique linéaire, on récupère en rebasant, puis on renvoie :


$ git pull --rebase
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
…
From /srv/essai
   c734180..2828f90  main       -> origin/main
Successfully rebased and updated refs/heads/main.
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 14 threads
Compressing objects: 100% (2/2), done.
…
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /srv/essai.git
   2828f90..725aae1  main -> main

$ git log --oneline --graph --all
* 725aae1 (HEAD -> main, origin/main, origin/HEAD) Ajoute Candide
* 2828f90 Ajoute Zadig
* c734180 Ajoute les notes

« Ajoute Candide » a été rejoué au-dessus de « Ajoute Zadig » (nouvelle empreinte, 725aae1), et l'envoi est une avance rapide. Ce rebase respecte la règle d'or : le commit rejoué n'avait jamais été envoyé.

Exercices semblables

Le cours du chapitre · Tous les exercices du chapitre