Outils du site

Des nouvelles de la Bourse : hausse de la chemise, baisse du pantalon et va-et-vient dans la fourrure ! [Coluche]

56-tools:git

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
56-tools:git [2019/02/12 08:41] – [Exemple] Roge56-tools:git [2023/12/13 01:08] (Version actuelle) – [Créer un repository bare] Roge
Ligne 65: Ligne 65:
 Avantage : l'origin est déjà préconfigurée dans le .git/config Avantage : l'origin est déjà préconfigurée dans le .git/config
  
 +
 +
 +===== Intialiser le remote à partir du local =====
 +
 +<code bash>
 +# Crée l'origin
 +git init <origin-repository> --bare
 +
 +# dans le dossier local racine
 +git remote add origin <URL>
 +# mise à jour de l'origin
 +git push origin master
 +# Tous les autres utilisateurs peuvent alors se synchroniser avec l'origin
 +git pull
 +</code>
 ===== Configuration ===== ===== Configuration =====
  
Ligne 146: Ligne 161:
 Afficher la liste des fichiers d'un projet : Afficher la liste des fichiers d'un projet :
  
-''git ls-tree <nowiki>–</nowiki>full-tree -r HEAD''+''git ls-tree %%--%%full-tree -r HEAD''
  
 Suppression définitive d'éléments : [[http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-git-repo|http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-git-repo]] Suppression définitive d'éléments : [[http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-git-repo|http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-git-repo]]
Ligne 178: Ligne 193:
 ===== Exemple ===== ===== Exemple =====
  
-''#-------------------------------------------------------------- # Configuration de Git #-------------------------------------------------------------- hal:/data/Test-Git $ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [branch "master"] remote = /bkp/GITs/Test-Git merge = refs/heads/master [remote "origin"] url = /bkp/GITs/Test-Git/ fetch = refs/heads/*:refs/remotes/origin/* push = master fetch = master #-------------------------------------------------------------- # Création du dossier de travail avec initialisation Git #-------------------------------------------------------------- hal:/data $ git init Test-Git Initialized empty Git repository in /media/data/Test-Git/.git/ #-------------------------------------------------------------- # Création du dossier de référence avec initialisation Git --bare #-------------------------------------------------------------- hal:/data $ cd /bkp/GITs/ hal:/bkp/GITs $ git init Test-Git --bare Initialized empty Git repository in /media/bkp/GITs/Test-Git/ hal:/bkp/GITs $ cd - /media/data hal:/data $ cd Test-Git/ hal:/data/Test-Git $ echo "v1" > test.txt hal:/data/Test-Git $ ll 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:/data/Test-Git $ git status On branch master Initial commit Untracked files: (use "git add < file>..." to include in what will be committed) test.txt nothing added to commit but untracked files present (use "git add" to track) #-------------------------------------------------------------- # Ajout dans Git #-------------------------------------------------------------- hal:/data/Test-Git $ git add * hal:/data/Test-Git $ git status On branch master Initial commit Changes to be committed: (use "git rm --cached < file>..." to unstage) new file: test.txt #-------------------------------------------------------------- # Commit #-------------------------------------------------------------- hal:/data/Test-Git $ git commit -m "v1" [master (root-commit) 95defef] v1 1 file changed, 1 insertion( ) create mode 100644 test.txt # Vérification hal:/data/Test-Git $ git log 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:/data/Test-Git $ git push /bkp/GITs/Test-Git/ 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 /bkp/GITs/Test-Git/ * [new branch] master -> master # Vérification hal:/data/Test-Git $ cd /bkp/GITs/Test-Git/ hal:/bkp/GITs/Test-Git $ 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:/data/Test-Git $ echo "v1.1" > test.txt hal:/data/Test-Git $ git status 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:/data/Test-Git $ git add * hal:/data/Test-Git $ git commit -m "v1.1" [master dd4b48d] v1.1 1 file changed, 1 insertion( ), 1 deletion(-) hal:/data/Test-Git $ git push /bkp/GITs/Test-Git/ master Counting objects: 3, done. Writing objects: 100% (3/3), 228 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To /bkp/GITs/Test-Git/ 95defef..dd4b48d master -> master hal:/data/Test-Git $ git log 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:/data/Test-Git $ echo "V1.2" > test.txt hal:/data/Test-Git $ git add * hal:/data/Test-Git $ git commit -m "V1.2" [master f9239f9] V1.2 1 file changed, 1 insertion( ), 1 deletion(-) hal:/data/Test-Git $ git push --set-upstream /bkp/GITs/Test-Git master Counting objects: 3, done. Writing objects: 100% (3/3), 230 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To /bkp/GITs/Test-Git dd4b48d..f9239f9 master -> master Branch master set up to track remote branch master from /bkp/GITs/Test-Git. #-------------------------------------------------------------- # Création d'une branche #-------------------------------------------------------------- hal:/data/Test-Git $ git checkout -b new-feature master Switched to a new branch 'new-feature' #-------------------------------------------------------------- # Création de changements #-------------------------------------------------------------- hal:/data/Test-Git $ echo "V1.3.0" > test.txt hal:/data/Test-Git $ git add * hal:/data/Test-Git $ git commit -m "start new feature" [new-feature f37b89e] start new feature 1 file changed, 1 insertion( ), 1 deletion(-) hal:/data/Test-Git $ echo "V1.3.1" > test.txt hal:/data/Test-Git $ git add * hal:/data/Test-Git $ git commit -m "End new feature" [new-feature 06f6e84] End new feature 1 file changed, 1 insertion( ), 1 deletion(-) hal:/data/Test-Git $ git log 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:/data/Test-Git $ git checkout master Switched to branch 'master' hal:/data/Test-Git $ git merge new-feature Updating 58f89b5..06f6e84 Fast-forward test.txt | 2 - 1 file changed, 1 insertion( ), 1 deletion(-) # Suppression de la branche hal:/data/Test-Git $ git branch -d new-feature Deleted branch new-feature (was 06f6e84). hal:/data/Test-Git $ git log 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:/data/Test-Git $ git push /bkp/GITs/Test-Git/ master 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 /bkp/GITs/Test-Git/ 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 ''+<code> 
 +#--------------------------------------------------------------  
 +# Configuration de Git  
 +#--------------------------------------------------------------  
 +hal:/data/Test-Git $ cat .git/config  
 +[core]  
 +repositoryformatversion = 0 filemode = true bare = false  
 +logallrefupdates = true  
 +[branch "master" 
 +remote = /bkp/GITs/Test-Git  
 +merge = refs/heads/master  
 +[remote "origin" 
 +url = /bkp/GITs/Test-Git/  
 +fetch = refs/heads 
 +/*:refs/remotes/origin*
 +push = master fetch = master  
 +#--------------------------------------------------------------  
 +# Création du dossier de travail avec initialisation Git  
 +#--------------------------------------------------------------  
 +hal:/data $ git init Test-Git  
 +Initialized empty Git repository in /media/data/Test-Git/.git/  
 +#--------------------------------------------------------------  
 +# Création du dossier de référence avec initialisation Git --bare  
 +#--------------------------------------------------------------  
 +hal:/data $ cd /bkp/GITs/  
 +hal:/bkp/GITs $ git init Test-Git --bare  
 +Initialized empty Git repository in /media/bkp/GITs/Test-Git/  
 +hal:/bkp/GITs $ cd - /media/data hal:/data  
 +$ cd Test-Git/  
 +hal:/data/Test-Git $ echo "v1" > test.txt  
 +hal:/data/Test-Git $ ll  
 +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:/data/Test-Git $ git status  
 +On branch master Initial commit  
 +Untracked files: (use "git add < file>..." to include in what will be committed)  
 +test.txt nothing added to commit but untracked files present (use "git add" to track)  
 +#-------------------------------------------------------------- #  
 +Ajout dans Git  
 +#--------------------------------------------------------------  
 +hal:/data/Test-Git $ git add *  
 +hal:/data/Test-Git $ git status  
 +On branch master Initial commit Changes to be committed:  
 +(use "git rm --cached < file>..." to unstage) new file: test.txt  
 +#--------------------------------------------------------------  
 +# Commit  
 +#--------------------------------------------------------------  
 +hal:/data/Test-Git $ git commit -m "v1"  
 +[master (root-commit) 95defef] v1 1 file changed, 1 insertion( ) create mode 100644 test.txt  
 +# Vérification  
 +hal:/data/Test-Git $ git log  
 +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:/data/Test-Git $ git push /bkp/GITs/Test-Git/  
 +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 /bkp/GITs/Test-Git/  
 +* [new branch] master -> master  
 +# Vérification  
 +hal:/data/Test-Git $ cd /bkp/GITs/Test-Git/  
 +hal:/bkp/GITs/Test-Git  
 +$ 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:/data/Test-Git $ echo "v1.1" > test.txt  
 +hal:/data/Test-Git $ git status  
 +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:/data/Test-Git $ git add *  
 +hal:/data/Test-Git $ git commit -m "v1.1"  
 +[master dd4b48d] v1.1 1  
 +file changed, 1 insertion( ), 1 deletion(-)  
 +hal:/data/Test-Git $ git push /bkp/GITs/Test-Git/ master  
 +Counting objects: 3, done.  
 +Writing objects: 100% (3/3), 228 bytes | 0 bytes/s, done.  
 +Total 3 (delta 0), reused 0 (delta 0) To /bkp/GITs/Test-Git/  
 +95defef..dd4b48d master -> master  
 +hal:/data/Test-Git $ git log  
 +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:/data/Test-Git $ echo "V1.2" > test.txt  
 +hal:/data/Test-Git $ git add *  
 +hal:/data/Test-Git $ git commit -m "V1.2"  
 +[master f9239f9] V1.2 1  
 +file changed, 1 insertion( ), 1 deletion(-)  
 +hal:/data/Test-Git $ git push --set-upstream /bkp/GITs/Test-Git master  
 +Counting objects: 3, done.  
 +Writing objects: 100% (3/3), 230 bytes | 0 bytes/s, done.  
 +Total 3 (delta 0), reused 0 (delta 0) To /bkp/GITs/Test-Git dd4b48d..f9239f9  
 +master -> master Branch master set up to track remote branch master from /bkp/GITs/Test-Git.  
 +#--------------------------------------------------------------  
 +# Création d'une branche  
 +#--------------------------------------------------------------  
 +hal:/data/Test-Git $ git checkout -b new-feature  
 +master Switched to a new branch 'new-feature'  
 +#--------------------------------------------------------------  
 +# Création de changements  
 +#--------------------------------------------------------------  
 +hal:/data/Test-Git $ echo "V1.3.0" > test.txt  
 +hal:/data/Test-Git $ git add *  
 +hal:/data/Test-Git $ git commit -m "start new feature"  
 +[new-feature f37b89e]  
 +start new feature 1 file changed, 1 insertion( ), 1 deletion(-)  
 +hal:/data/Test-Git $ echo "V1.3.1" > test.txt  
 +hal:/data/Test-Git $ git add *  
 +hal:/data/Test-Git $ git commit -m "End new feature"  
 +[new-feature 06f6e84] End new feature 1 file changed, 1 insertion( ), 1 deletion(-)  
 +hal:/data/Test-Git $ git log  
 +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:/data/Test-Git $ git checkout master Switched to branch 'master'  
 +hal:/data/Test-Git $ git merge new-feature  
 +Updating 58f89b5..06f6e84 Fast-forward test.txt | 2 - 1 file changed, 1 insertion( ), 1 deletion(-)  
 +# Suppression de la branche  
 +hal:/data/Test-Git $ git branch -d new-feature  
 +Deleted branch new-feature (was 06f6e84).  
 +hal:/data/Test-Git $ git log  
 +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:/data/Test-Git $ git push /bkp/GITs/Test-Git/ master  
 +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 /bkp/GITs/Test-Git/  
 +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  
 +</code>
  
  
Dernière modification : 2019/02/12 08:41