Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
56-tools:git [2019/02/10 11:20] – [Git stash] Roge | 56-tools:git [2023/12/13 01:08] (Version actuelle) – [Créer un repository bare] Roge | ||
---|---|---|---|
Ligne 65: | Ligne 65: | ||
Avantage : l' | Avantage : l' | ||
+ | |||
+ | |||
+ | ===== Intialiser le remote à partir du local ===== | ||
+ | |||
+ | <code bash> | ||
+ | # Crée l' | ||
+ | git init < | ||
+ | |||
+ | # dans le dossier local racine | ||
+ | git remote add origin <URL> | ||
+ | # mise à jour de l' | ||
+ | git push origin master | ||
+ | # Tous les autres utilisateurs peuvent alors se synchroniser avec l' | ||
+ | git pull | ||
+ | </ | ||
===== Configuration ===== | ===== Configuration ===== | ||
Ligne 142: | Ligne 157: | ||
- | ===== Git checkout | + | ===== SOS ===== |
- | on peut récupérer | + | Afficher |
- | '' | + | '' |
+ | |||
+ | Suppression définitive d' | ||
+ | |||
+ | Récupérer uniquement quelques fichiers : | ||
+ | |||
+ | '' | ||
+ | |||
+ | Normalement Git ne supprime pas de commit, donc si on est perdu : | ||
+ | |||
+ | '' | ||
+ | |||
+ | On peut alors revenir sur un commit particulier avec : | ||
+ | |||
+ | '' | ||
+ | |||
+ | If you want to get list of changed files: | ||
+ | |||
+ | '' | ||
+ | |||
+ | If you want to get list of all files in a commit, you can use | ||
+ | |||
+ | '' | ||
+ | ===== Pull - fetch ===== | ||
+ | |||
+ | La commande **git fetch** va récupérer toutes les données des commits effectués sur la branche courante qui n' | ||
+ | |||
+ | La commande **git pull** est en fait la commande qui regroupe les commandes **git fetch** suivie de **git merge**. Cette commande télécharge les données des commits qui n'ont pas encore été récupérées dans votre branche locale puis fusionne ensuite ces données. | ||
+ | |||
+ | |||
+ | ===== Exemple ===== | ||
+ | |||
+ | < | ||
+ | # | ||
+ | # Configuration de Git | ||
+ | # | ||
+ | hal:/ | ||
+ | [core] | ||
+ | repositoryformatversion = 0 filemode = true bare = false | ||
+ | logallrefupdates = true | ||
+ | [branch " | ||
+ | remote = / | ||
+ | merge = refs/ | ||
+ | [remote " | ||
+ | url = / | ||
+ | fetch = refs/ | ||
+ | / | ||
+ | push = master fetch = master | ||
+ | # | ||
+ | # Création du dossier de travail avec initialisation Git | ||
+ | # | ||
+ | hal:/data $ git init Test-Git | ||
+ | Initialized empty Git repository in / | ||
+ | # | ||
+ | # Création du dossier de référence avec initialisation Git --bare | ||
+ | # | ||
+ | hal:/data $ cd /bkp/GITs/ | ||
+ | hal:/ | ||
+ | Initialized empty Git repository in / | ||
+ | hal:/ | ||
+ | $ cd Test-Git/ | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | total 8 drwxr-xr-x 7 roge roge 4096 Nov 9 09:08 .git -rw-r--r-- 1 roge roge 3 Nov 9 09:10 test.txt | ||
+ | # | ||
+ | # Status | ||
+ | # | ||
+ | hal:/ | ||
+ | On branch master Initial commit | ||
+ | Untracked files: (use "git add < file> | ||
+ | test.txt nothing added to commit but untracked files present (use "git add" to track) | ||
+ | # | ||
+ | Ajout dans Git | ||
+ | # | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | On branch master Initial commit Changes to be committed: | ||
+ | (use "git rm --cached < file> | ||
+ | # | ||
+ | # Commit | ||
+ | # | ||
+ | hal:/ | ||
+ | [master (root-commit) 95defef] v1 1 file changed, 1 insertion( ) create mode 100644 test.txt | ||
+ | # Vérification | ||
+ | hal:/ | ||
+ | 2016-11-09 12:38 (HEAD -> master) dd4b48d roge v1.1 | ||
+ | 2016-11-09 09:10 95defef roge v1 | ||
+ | # | ||
+ | Mise à jour du repository de reference | ||
+ | # | ||
+ | hal:/ | ||
+ | master Counting objects: 3, done. Writing objects: 100% (3/3), 197 bytes | 0 bytes/s, done. | ||
+ | Total 3 (delta 0), reused 0 (delta 0) To / | ||
+ | * [new branch] master -> master | ||
+ | # Vérification | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | $ git log | ||
+ | 2016-11-09 12:38 (HEAD -> master) dd4b48d roge v1.1 | ||
+ | 2016-11-09 09:10 95defef roge v1 | ||
+ | # | ||
+ | # Modification du fichier et commit | ||
+ | # | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | On branch master | ||
+ | Changes not staged for commit: (use "git add < file> | ||
+ | to update what will be committed) (use "git checkout -- < file> | ||
+ | to discard changes in working directory) | ||
+ | modified: test.txt no changes added to commit (use "git add" and/or "git commit -a") | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | [master dd4b48d] v1.1 1 | ||
+ | file changed, 1 insertion( ), 1 deletion(-) | ||
+ | hal:/ | ||
+ | Counting objects: 3, done. | ||
+ | Writing objects: 100% (3/3), 228 bytes | 0 bytes/s, done. | ||
+ | Total 3 (delta 0), reused 0 (delta 0) To / | ||
+ | 95defef..dd4b48d master -> master | ||
+ | hal:/ | ||
+ | 2016-11-09 12:38 (HEAD -> master) dd4b48d roge v1.1 | ||
+ | 2016-11-09 09:10 95defef roge v1 | ||
+ | # | ||
+ | # 3ième modification du fichier | ||
+ | # | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | [master f9239f9] V1.2 1 | ||
+ | file changed, 1 insertion( ), 1 deletion(-) | ||
+ | hal:/ | ||
+ | Counting objects: 3, done. | ||
+ | Writing objects: 100% (3/3), 230 bytes | 0 bytes/s, done. | ||
+ | Total 3 (delta 0), reused 0 (delta 0) To / | ||
+ | master -> master Branch master set up to track remote branch master from / | ||
+ | # | ||
+ | # Création d'une branche | ||
+ | # | ||
+ | hal:/ | ||
+ | master Switched to a new branch ' | ||
+ | # | ||
+ | # Création de changements | ||
+ | # | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | [new-feature f37b89e] | ||
+ | start new feature 1 file changed, 1 insertion( ), 1 deletion(-) | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | [new-feature 06f6e84] End new feature 1 file changed, 1 insertion( ), 1 deletion(-) | ||
+ | hal:/ | ||
+ | 2016-11-09 13:15 (HEAD -> new-feature) 06f6e84 roge End new feature | ||
+ | 2016-11-09 13:14 f37b89e roge start new feature | ||
+ | 2016-11-09 13:02 (master) 58f89b5 roge V1.2.2 | ||
+ | 2016-11-09 13:02 71f0700 roge V1.2.1 | ||
+ | 2016-11-09 12:56 (test-feature) f9239f9 roge V1.2 | ||
+ | 2016-11-09 12:38 dd4b48d roge v1.1 | ||
+ | 2016-11-09 09:10 95defef roge v1 | ||
+ | # | ||
+ | # Merge: test-feature --> master | ||
+ | # | ||
+ | hal:/ | ||
+ | hal:/ | ||
+ | Updating 58f89b5..06f6e84 Fast-forward test.txt | 2 - 1 file changed, 1 insertion( ), 1 deletion(-) | ||
+ | # Suppression de la branche | ||
+ | hal:/ | ||
+ | Deleted branch new-feature (was 06f6e84). | ||
+ | hal:/ | ||
+ | 2016-11-09 13:15 (HEAD -> master) 06f6e84 roge End new feature | ||
+ | 2016-11-09 13:14 f37b89e roge start new feature | ||
+ | 2016-11-09 13:02 58f89b5 roge V1.2.2 | ||
+ | 2016-11-09 13:02 71f0700 roge V1.2.1 | ||
+ | 2016-11-09 12:56 (test-feature) f9239f9 roge V1.2 | ||
+ | 2016-11-09 12:38 dd4b48d roge v1.1 | ||
+ | 2016-11-09 09:10 95defef roge v1 | ||
+ | # | ||
+ | # Mise à jour du repository de reference | ||
+ | # | ||
+ | hal:/ | ||
+ | Counting objects: 12, done. | ||
+ | Delta compression using up to 8 threads. | ||
+ | Compressing objects: 100% (4/4), done. | ||
+ | Writing objects: 100% (12/12), 852 bytes | 0 bytes/s, done. | ||
+ | Total 12 (delta 0), reused 0 (delta 0) To / | ||
+ | f9239f9..06f6e84 master -> master | ||
+ | # Vérification | ||
+ | 2016-11-09 13:15 (HEAD -> master) 06f6e84 roge End new feature | ||
+ | 2016-11-09 13:14 f37b89e roge start new feature | ||
+ | 2016-11-09 13:02 58f89b5 roge V1.2.2 | ||
+ | 2016-11-09 13:02 71f0700 roge V1.2.1 | ||
+ | 2016-11-09 12:56 f9239f9 roge V1.2 | ||
+ | 2016-11-09 12:38 dd4b48d roge v1.1 | ||
+ | 2016-11-09 09:10 95defef roge v1 | ||
+ | </ | ||
- | ou récupérer uniquement quelques fichiers : | ||
- | '' | ||
===== Git tag ===== | ===== Git tag ===== | ||
Ligne 196: | Ligne 404: | ||
On crée un user //git// groupe //git// qui sera propriétaire des projets sur le repository distant. | On crée un user //git// groupe //git// qui sera propriétaire des projets sur le repository distant. | ||
- | < | + | < |
- | sudo groupadd git | + | sudo groupadd git |
- | sudo useradd -g git git | + | sudo useradd -g git git |
- | sudo -i | + | sudo -i |
- | passwd git | + | passwd git |
</ | </ | ||
Dans le fichier // | Dans le fichier // | ||
- | < | + | < |
[remote " | [remote " | ||
- | url = git@:/ | + | url = git@< server>:/ |
fetch = +refs/ | fetch = +refs/ | ||
push = master fetch = master | push = master fetch = master | ||
- | < | + | </code> |
- | Les ' | + | Les ' |
- | < | + | < |
- | sudo usermod -a -G //git// //< | + | sudo usermod -a -G git < |
</ | </ | ||
- | ===== Git branch ===== | ||
- | https:// | + | ===== Git branch ===== |
+ | |||
+ | https:// | ||
+ | |||
+ | |||
+ | Liste des branches existantes : | ||
- | Liste des branches existantes : | + | '' |
- | '' | + | Créer une nouvelle branche : |
- | Créer une nouvelle branche : | + | '' |
- | '' | + | Utiliser la nouvelle branche : |
- | Utiliser la nouvelle branche : '' | + | '' |
Les deux en un (Créer une branche et l' | Les deux en un (Créer une branche et l' | ||
- | '' | + | '' |
- | Ajout de modifications : | ||
- | '' | + | Ajout de modifications : |
- | '' | + | |
- | … plusieurs fois … | + | '' |
- | ==== Git Merge ==== | + | '' |
- | Pour les workflow en " | + | ... plusieurs fois ... |
- | Avant de merger : | ||
- | '' | + | ==== Git Merge ==== |
- | Effectuer le merge de la branche //**new-feature**// | + | Pour les workflow en "branche" (//Feature Branch Workflow//). Les développers ne travaillent que sur des branches. |
+ | On ne merge pas immédiatement les branches sur le master | ||
- | ''git merge //< | + | Ce workflow est utilisé pour l'intégration continue. |
- | Correction de conflits éventuels … | ||
- | '' | + | Avant de merger : |
- | Mettre à jour l'origine en sans conserver la branche : | + | ''git checkout master'' |
- | '' | ||
- | Mettre à jour l' | + | Effectuer le merge de la branche //**new-feature**// créée précédemment: |
- | '' | + | '' |
- | A la fin on peut merger la branche sur //origin// : | ||
- | '' | + | Correction de conflits éventuels ... |
- | ==== Git Rebase ==== | + | '' |
- | Pour les workflows " | ||
- | Garantir que le //master// de l'// | + | Mettre |
- | Les développements se font dans des branches dédiées en local et que c'est OK on envoi sur le //master// de l'//origin//. | + | '' |
- | Avant de merger | + | Mettre à jour l' |
- | '' | + | '' |
- | Les conflits éventuels sont signalés. | ||
- | '' | + | A la fin on peut merger la branche sur //origin// : |
- | Après correction de conflits : | + | <code bash> |
+ | git checkout master | ||
+ | git pull | ||
+ | git pull origin < | ||
+ | git push | ||
+ | </ | ||
- | '' | + | ==== Git Rebase ==== |
- | Si on veut arreter | + | Pour les workflows |
- | '' | + | Avant de merger : |
- | Mettre à jour l'origine: | + | ''git pull %%--%%rebase origin master'' |
- | '' | + | Les conflits éventuels sont signalés. |
- | ===== Git stash ===== | + | '' |
- | git stash permet | + | Après correction |
+ | '' | ||
- | < | + | Si on veut arreter " |
- | hal:/data/test2 $ echo Test stash… | + | |
- | > test.txt hal:/ | + | |
- | $ git status On branch master Your branch is ahead of ' | + | |
- | Changes not staged for commit: (use git add | + | |
- | >…to update what will be committed) (use > git checkout – > | + | |
- | … to discard changes in working directory) modified: test.txt no changes added to commit (use > git add and/or > git commit -a) hal:/ | + | |
- | $ git stash Saved working directory and index state WIP on master: a4fcdc4 Bla bla ..2 .. | + | '' |
- | HEAD is now at a4fcdc4 Bla bla ..2 | + | |
- | .. hal:/ | + | |
- | use git push to publish your local commits) nothing to commit, working directory clean | + | |
- | </ | + | |
- | Pour récupérer le contenu du "// | ||
- | '' hal:/data/test2 $ git stash pop On branch master Your branch is ahead of ' | + | Mettre à jour l'origine: |
- | On peut aussi empliler les stash : | + | '' |
- | '' | + | ===== Git stash ===== |
- | ===== SOS ===== | + | git stash permet de mettre de coté un état **local** (sorte de commit local uniquement). |
- | Afficher la liste des fichiers d'un projet | + | <code bash> |
+ | hal:/data/test2 $ echo "Test stash..." | ||
- | '' | + | hal:/ |
+ | On branch master | ||
+ | Your branch is ahead of 'origin/ | ||
+ | (use "git push" to publish your local commits) | ||
+ | Changes not staged for commit: | ||
+ | (use "git add <file>..." to update what will be committed) | ||
+ | (use "git checkout | ||
- | Suppression définitive d' | + | modified: test.txt |
- | Récupérer uniquement quelques fichiers : | + | no changes added to commit (use "git add" and/or "git commit -a") |
- | '' | + | hal:/ |
+ | Saved working directory and index state WIP on master: a4fcdc4 Bla bla ..2 .. | ||
+ | HEAD is now at a4fcdc4 Bla bla ..2 .. | ||
- | Normalement Git ne supprime pas de commit, | + | hal:/ |
+ | On branch master | ||
+ | Your branch is ahead of ' | ||
+ | (use "git push" to publish your local commits) | ||
+ | nothing to commit, | ||
+ | </ | ||
- | '' | + | Pour récupérer le contenu du "// |
- | On peut alors revenir sur un commit | + | <code bash> |
+ | hal:/ | ||
+ | On branch master | ||
+ | Your branch is ahead of ' | ||
+ | (use "git push" to publish your local commits) | ||
+ | Changes not staged for commit: | ||
+ | (use "git add < | ||
+ | (use "git checkout -- < | ||
- | '' | + | modified: test.txt |
- | If you want to get list of changed files: | + | no changes added to commit (use "git add" and/or "git commit -a") |
+ | Dropped refs/ | ||
- | '' | + | </code> |
- | If you want to get list of all files in a commit, you can use | + | On peut aussi empliler les stash : |
- | '' | + | <code bash> |
+ | hal:/ | ||
+ | hal:/ | ||
+ | Saved working directory and index state WIP on master: a4fcdc4 Bla bla ..2 .. | ||
+ | HEAD is now at a4fcdc4 Bla bla ..2 .. | ||
+ | |||
+ | hal:/ | ||
+ | hal:/ | ||
+ | Saved working directory and index state WIP on master: a4fcdc4 Bla bla ..2 .. | ||
+ | HEAD is now at a4fcdc4 Bla bla ..2 .. | ||
+ | |||
+ | hal:/ | ||
+ | stash@{0}: WIP on master: a4fcdc4 Bla bla ..2 .. | ||
+ | stash@{1}: WIP on master: a4fcdc4 Bla bla ..2 .. | ||
+ | hal:/ | ||
+ | |||
+ | # A la fin on peut supprimer les stashs : | ||
+ | |||
+ | hal:/ | ||
+ | Dropped stash@{1} (18d40066b10557b8551ac28b7f96c2d1ceb8b23d) | ||
+ | hal:/ | ||
+ | Dropped stash@{0} (9d7208791ae7de2a2af1ba0a79532008ac128786) | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ===== SOS ===== | ||
+ | |||
+ | Afficher la liste des fichiers d'un projet : | ||
+ | |||
+ | '' | ||
+ | |||
+ | Suppression définitive d' | ||
+ | |||
+ | http:// | ||
+ | |||
+ | |||
+ | Récupérer uniquement quelques fichiers : | ||
+ | |||
+ | '' | ||
+ | |||
+ | |||
+ | Normalement Git ne supprime pas de commit, donc si on est perdu : | ||
+ | |||
+ | '' | ||
+ | |||
+ | On peut alors revenir sur un commit particulier avec : | ||
+ | |||
+ | '' | ||
+ | |||
+ | https:// | ||
+ | |||
+ | If you want to get list of changed files: | ||
+ | |||
+ | '' | ||
+ | If you want to get list of all files in a commit, you can use | ||
+ | '' | ||
===== Exemple ===== | ===== Exemple ===== | ||