{{tag>Brouillon git}} # Git gestion des conflits merge Voir : * [How to resolve Git merge conflicts](https://opensource.com/article/23/4/resolve-git-merge-conflicts) * [Drop git pull for fetch and rebase](https://developers.redhat.com/articles/2023/09/07/drop-git-pull-fetch-and-rebase) * Mais remplacez `git push --force` par `git push --force-with-lease` * https://blog.stack-labs.com/code/git_force_with_lease/ * https://www.dynamic-mess.com/developpement/git-merge-fast-forward-rebase-culture-git/ * https://nitaym.github.io/ourstheirs/ * https://saturn.ffzg.hr/rot13/index.cgi?action=display_html;page_name=git * https://gist.github.com/karenyyng/f19ff75c60f18b4b8149 Undo uncommited \ remove any non-committed changes.\ Par exemple pour annuler un pb de merge ~~~bash git checkout -f ~~~ Résolution de conflit ~~~bash git checkout master git merge --no-ff --no-commit branch_feature # git merge --no-ff --no-commit branch_feature --no-edit #ou Pour cacher les micro-commits #git merge --squash branch_feature ~~~ Source : http://www.journaldunet.com/developpeur/pratique/developpement/12267/comment-gerer-un-conflit-de-fusion-dans-git.html Si **both modified** ~~~bash git checkout --ours fichier.txt # Version originale git checkout --theirs fichier.txt # Version modifiée git add fichier # Ajout de la version du fichier que l'on a choisie git commit fichier # Mise à jour du dépôt avec la nouvelle version du fichier #ou git merge --continue ~~~ Git diff ours theirs Git diff précédente version et les modifs des autres (**theirs**) ~~~bash git diff :1:tasks/main.yml :3:tasks/main.yml ~~~ Git diff précédente version et nos modifs (**ours**) ~~~bash git diff :1:tasks/main.yml :2:tasks/main.yml ~~~ Il existe aussi une commande permettant de voir les différents changements entre les versions dans un fichier. Cette commande affiche dans le fichier sur les sections modifiées trois versions : les changements que l'on a effectués, les changements effectués dans la branche par d'autres développeurs et l'ancêtre commun des deux fichiers : Commande pour afficher les changements dans les fichiers. ~~~bash git config merge.conflictstyle diff3 ~~~ List files which have conflicts ~~~bash git ls-files --unmerged ~~~ Mark conflict resolved ~~~bash git update-index target-ppc/cpu.h ~~~ En cas de conflits ~~~bash git mergetool ~~~ ## Doc Gitlab à propos de la résolution de conflits Check out, review, and merge locally Step 1. Fetch and check out the branch for this merge request ~~~bash git fetch origin git checkout -b "master" "origin/master" ~~~ Step 2. Review the changes locally Step 3. Merge the branch and fix any conflicts that come up ~~~bash git fetch origin git checkout "dev" git merge --no-ff "master" ~~~ Step 4. Push the result of the merge to GitLab ~~~bash git push origin "dev" Tip: You can also checkout merge requests locally by following these guidelines https://gitlab.acme.fr/help/user/project/merge_requests/reviewing_and_managing_merge_requests.md#checkout-merge-requests-locally-through-the-head-ref ~~~