Créer un conflit
Lorsqu'un conflit survient, vous devez le résoudre pour terminer votre travail. Dans cette étape, nous allons délibérément créer un conflit à partir de nos deux référentiels existants, « tutorial » et « tutorial2 ».
Ouvrez tout d'abord le fichier sample.txt dans le répertoire tutorial. Ajoutez le texte en gras ci-dessous au fichier et validez la modification, sans la transférer à ce stade.
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
commit: Save the status of an index
$ git add sample.txt
$ git commit -m "append description of the commit command"
  [main 95f15c9] append description of the commit command
    1 files changed, 1 insertions(+), 0 deletions(-)
Ouvrez ensuite le fichier sample.txt dans le répertoire tutorial2. Ajoutez le texte en gras ci-dessous au fichier et validez.
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
pull: Obtain the content of the remote repository
$ git add sample.txt
$ git commit -m "append description of the pull command"
  [main 4c01823] append description of the pull command
    1 files changed, 1 insertions(+), 0 deletions(-)
Utilisez ensuite la commande git push pour transférer la modification apportée dans le fichier « tutorial2 » vers le référentiel distant.
$ git push
  Username: <username>
  Password: <password>
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects: 100% (2/2), done.
  Writing objects: 100% (3/3), 391 bytes, done.
  Total 3 (delta 0), reused 0 (delta 0)
  To https://example.backlog.com/git/BLGGIT/tutorial.git
      3da09c1..4c01823  main -> main
Dans notre référentiel distant actif, le fichier sample.txt contient la troisième ligne pull: Obtain the content of the remote repository et il a été validé dans le journal historique.
Nous allons ensuite transférer le commit de notre référentiel tutorial vers le référentiel distant.
$ git push
  Username: <username>
  Password: <password>
  To https://example.backlog.com/git/BLGGIT/tutorial.git
  ! [rejected]        main -> main (non-fast-forward)
  error: failed to push some refs to 'https://example.backlog.com/git/BLGGIT/tutorial.git'
  To prevent you from losing history, non-fast-forward updates were rejected
  Merge the remote changes (e.g. 'git pull') before pushing again.  See the
  'Note about fast-forwards' section of 'git push --help' for details.
Comme vous pouvez le constater, Git génère un conflit et rejette votre transfert.