Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| memo:git [15/04/2016 16:41] – Lister changements d'un commit Arnaud Jacquemin | memo:git [10/12/2024 11:39] (Version actuelle) – Gestion des branches Arnaud Jacquemin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Git====== | ====== Git====== | ||
| + | |||
| + | ===== Récupérer sources depuis un dépôt ===== | ||
| + | |||
| + | <code bash> | ||
| + | git clone git@framagit.org: | ||
| + | </ | ||
| + | |||
| + | Pour Framagit, renseigner au préalable dans les paramètres du compte la clé publique du PC, à récuperer dans '' | ||
| + | |||
| + | |||
| + | ===== Récupérer les changements d'un dépôt distant ===== | ||
| + | |||
| + | Resynchronise le dépôt local avec le dépôt distant. Ne change rien dans l' | ||
| + | |||
| + | <code bash> | ||
| + | # Avec " | ||
| + | git fetch origin | ||
| + | </ | ||
| + | |||
| + | ===== Gestion des branches ===== | ||
| + | |||
| + | Créer une branche : ((https:// | ||
| + | <code bash> | ||
| + | git branch nomdelabranche | ||
| + | </ | ||
| + | |||
| + | Basculer sur cette branche : ((https:// | ||
| + | <code bash> | ||
| + | git checkout nomdelabranche | ||
| + | </ | ||
| + | |||
| + | Faire ces deux actions (créer et basculer sur une nouvelle branche) en une seule commande avec un raccourci : ((https:// | ||
| + | <code bash> | ||
| + | git checkout -b nomdelabranche | ||
| + | </ | ||
| + | |||
| + | Fusionner les changements d'une autre branche (de //hotfix// vers //main// dans cet exemple) : | ||
| + | <code bash> | ||
| + | git checkout main | ||
| + | git merge hotfix | ||
| + | </ | ||
| + | |||
| + | Re-baser son travail sur une autre branche, par exemple avant de demander la fusion de ses changements dans cette branche. Résultat similaire à un '' | ||
| + | ⚠️ À ne pas faire sur une branche publique qui a potentiellement servi de base à d' | ||
| + | <code bash> | ||
| + | # Re-baser l' | ||
| + | git rebase develop | ||
| + | </ | ||
| + | |||
| + | Obtenir la liste des branches : | ||
| + | <code bash> | ||
| + | git branch | ||
| + | # Uniquement celles qui n'ont pas encore été fusionnées : | ||
| + | git branch --no-merged | ||
| + | </ | ||
| + | |||
| + | Supprimer une branche : | ||
| + | <code bash> | ||
| + | git branch -d hotfix | ||
| + | </ | ||
| + | |||
| + | Renommer une branche, par exemple de //master// vers //main// ((https:// | ||
| + | <code bash> | ||
| + | git branch --move master main | ||
| + | # L' | ||
| + | git push --set-upstream origin main | ||
| + | # Supprimer l' | ||
| + | git push origin --delete master | ||
| + | # Vérifier le résultat : | ||
| + | git branch --all | ||
| + | </ | ||
| + | |||
| + | ===== Obtenir statut de l' | ||
| + | |||
| + | <code bash> | ||
| + | git status | ||
| + | </ | ||
| + | |||
| ===== Créer dépôt de travail à partir de sources ===== | ===== Créer dépôt de travail à partir de sources ===== | ||
| Ligne 21: | Ligne 99: | ||
| <code bash> | <code bash> | ||
| git clone --bare my_project my_project.git | git clone --bare my_project my_project.git | ||
| + | </ | ||
| + | |||
| + | Exemple avec un dossier SMB (sous windows) | ||
| + | |||
| + | <code dos> | ||
| + | git clone --bare " | ||
| + | </ | ||
| + | |||
| + | Exemple sous Linux | ||
| + | <code bash> | ||
| + | git clone --bare ~/ | ||
| </ | </ | ||
| Ligne 43: | Ligne 132: | ||
| <code bash> | <code bash> | ||
| - | git remote add origin "///Efiles.feel-it.mad\xanit\sources_dvpt\git\gdm\ecommerce\ExportJobGDMToSparkow.git" | + | git remote add origin "///serveur-de-fichiers\dossier\depot.git" |
| </ | </ | ||
| - | Remplacer | + | Si besoin remplacer |
| - | ==== Changer URL ==== | + | ==== Modifier |
| <code bash> | <code bash> | ||
| - | $ git remote set-url origin "///Efiles.feel-it.mad\xanit\sources_dvpt\git\gdm\ecommerce\flux-probance.git" | + | # Changer l'URL d'un dépôt distant |
| + | $ git remote set-url origin "….git" | ||
| + | |||
| + | # Renommer un dépôt distant | ||
| + | $ git remote rename origin newname | ||
| </ | </ | ||
| - | Remplacer '' | + | Remplacer '' |
| Ligne 69: | Ligne 162: | ||
| + | ===== Comparer deux branches ===== | ||
| + | |||
| + | Liste tous les fichiers qui diffèrent entre deux branches : | ||
| + | |||
| + | <code bash> | ||
| + | git diff --stat=120 branche1..branche2 | ||
| + | </ | ||
| + | |||
| + | Source : http:// | ||
| ===== Changer date d'un commit ===== | ===== Changer date d'un commit ===== | ||
| Ligne 82: | Ligne 184: | ||
| Source : http:// | Source : http:// | ||
| + | ===== Changer auteur d'un commit ===== | ||
| + | |||
| + | <file bash git-author-rewrite.sh> | ||
| + | #!/bin/sh | ||
| + | |||
| + | git filter-branch --env-filter ' | ||
| + | |||
| + | OLD_EMAIL=" | ||
| + | CORRECT_NAME=" | ||
| + | CORRECT_EMAIL=" | ||
| + | |||
| + | if [ " | ||
| + | then | ||
| + | export GIT_COMMITTER_NAME=" | ||
| + | export GIT_COMMITTER_EMAIL=" | ||
| + | fi | ||
| + | if [ " | ||
| + | then | ||
| + | export GIT_AUTHOR_NAME=" | ||
| + | export GIT_AUTHOR_EMAIL=" | ||
| + | fi | ||
| + | ' --tag-name-filter cat -- --branches --tags | ||
| + | </ | ||
| ===== Annuler un commit ===== | ===== Annuler un commit ===== | ||
| Ligne 130: | Ligne 255: | ||
| <code bash> | <code bash> | ||
| - | ssh login@ssh.cluster006.ovh.net | + | LOGINOVH=login |
| + | ssh ${LOGINOVH}@ssh.cluster006.ovh.net | ||
| #Sur le serveur OVH | #Sur le serveur OVH | ||
| - | mkdir -p ~/sources/nom_projet.git | + | NOMPROJET=nom_projet |
| - | cd ~/sources/nom_projet.git | + | mkdir -p ~/sources/${NOMPROJET}.git |
| + | cd ~/sources/${NOMPROJET}.git | ||
| git init --bare | git init --bare | ||
| </ | </ | ||
| Ligne 139: | Ligne 266: | ||
| <code bash> | <code bash> | ||
| #En local | #En local | ||
| - | cd ./nom_projet | + | NOMPROJET=nom_projet |
| - | git remote add ovh ssh://login@ssh.cluster006.ovh.net/ | + | LOGINOVH=login |
| + | cd ./${NOMPROJET} | ||
| + | git remote add ovh ssh://${LOGINOVH}@ssh.cluster006.ovh.net/ | ||
| git push ovh master | git push ovh master | ||
| </ | </ | ||
| Ligne 166: | Ligne 295: | ||
| Source : http:// | Source : http:// | ||
| + | |||
| + | |||
| + | ===== Supprimer toutes les modifications locales ===== | ||
| + | |||
| + | Remove untracked files from the current directory as well as any files that Git usually ignores. | ||
| + | |||
| + | <code bash> | ||
| + | # Undo changes in tracked files | ||
| + | git reset --hard | ||
| + | # Remove untracked files | ||
| + | git clean -df | ||
| + | </ | ||
| + | |||
| + | Source : https:// | ||
| + | |||