Projet

Général

Profil

GitBonnesPratiques » Historique » Version 26

Emmanuel GARETTE, 27/07/2011 10:47

1 1 Redmine Admin
{{toc}}
2 1 Redmine Admin
3 15 Gwenael Remond
4 1 Redmine Admin
h1. Présentation
5 1 Redmine Admin
6 1 Redmine Admin
Site officiel : http://git-scm.com/
7 1 Redmine Admin
8 1 Redmine Admin
Tutoriaux intéressants : 
9 1 Redmine Admin
* http://team.gcu.info/~ange/git_article/
10 1 Redmine Admin
* le tutorial des man pages http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
11 1 Redmine Admin
* http://gitready.com/
12 1 Redmine Admin
* http://progit.org/book/
13 1 Redmine Admin
* http://www.unixgarden.com/index.php/administration-systeme/git-pour-les-futurs-barbus
14 7 Gaston TJEBBES
* http://yannesposito.com/Scratch/fr/blog/2010-03-22-Git-Tips/
15 1 Redmine Admin
16 1 Redmine Admin
Les manpages des commandes sont accessibles avec la commande help directement, 
17 1 Redmine Admin
par exemple : 
18 1 Redmine Admin
<pre>
19 1 Redmine Admin
git help log
20 1 Redmine Admin
</pre>
21 1 Redmine Admin
22 6 Redmine Admin
*remarque* : Il faut utiliser une version récente de git-core (>1.6.3) pour pouvoir travailler avec les dépôts. 
23 3 samuel morin
24 14 Klaas TJEBBES
h1. Paramétrage global
25 1 Redmine Admin
26 1 Redmine Admin
Il est nécessaire de déclarer vos noms et emails dans votre configuration git globale
27 1 Redmine Admin
<pre>
28 1 Redmine Admin
git config --global user.name "Prénom NOM"
29 1 Redmine Admin
git config --global user.email "prenom.nom@ac-acad.fr"
30 1 Redmine Admin
</pre>
31 1 Redmine Admin
32 14 Klaas TJEBBES
Afin que le git ne demande plus de login/pass , il faut renseigner le fichier @~/.netrc@ :
33 1 Redmine Admin
<pre>
34 14 Klaas TJEBBES
machine dev-eole.ac-dijon.fr
35 14 Klaas TJEBBES
login monlogin
36 14 Klaas TJEBBES
password monmotdepasse
37 14 Klaas TJEBBES
</pre>
38 14 Klaas TJEBBES
et paramétrer les droits du fichier :
39 14 Klaas TJEBBES
<pre>
40 14 Klaas TJEBBES
chmod 600 ~/.netrc
41 14 Klaas TJEBBES
</pre>
42 14 Klaas TJEBBES
43 14 Klaas TJEBBES
h1. Premiers pas
44 14 Klaas TJEBBES
45 23 Redmine Admin
* Démarrer un nouveau projet.
46 23 Redmine Admin
47 23 Redmine Admin
Demandez à l’administrateur Eole la création de votre projet dans le RedMine.
48 23 Redmine Admin
49 23 Redmine Admin
* Premier Commit du projet.
50 23 Redmine Admin
51 23 Redmine Admin
d'abord récupérer le projet :
52 23 Redmine Admin
<pre>
53 23 Redmine Admin
git clone http://login@dev-eole.ac-dijon.fr/git/nom_projet
54 23 Redmine Admin
</pre>
55 23 Redmine Admin
56 23 Redmine Admin
remarquons bien que le projet initialisé est *vide*
57 23 Redmine Admin
58 23 Redmine Admin
ensuite, aller dans le dossier du nom_projet, ajouter au moins un fichier, 
59 23 Redmine Admin
puis 
60 23 Redmine Admin
61 23 Redmine Admin
<pre>
62 23 Redmine Admin
git add fichier1 fichier2 fichier3
63 23 Redmine Admin
</pre>
64 23 Redmine Admin
65 23 Redmine Admin
<pre>
66 23 Redmine Admin
git commit -m"permière version"
67 23 Redmine Admin
</pre>
68 23 Redmine Admin
69 23 Redmine Admin
maintenant la branche master doit être apparue (puisqu'il y a des fichiers dans le projet), donc
70 23 Redmine Admin
71 23 Redmine Admin
<pre>
72 23 Redmine Admin
git branch
73 23 Redmine Admin
</pre>
74 23 Redmine Admin
doit lister la branche @master@
75 23 Redmine Admin
76 23 Redmine Admin
pour finir , faire un "push" pour envoyer les fichiers sur le dépot de code : 
77 23 Redmine Admin
<pre>
78 23 Redmine Admin
git push http://login@dev-eole.ac-dijon.fr/git/nom_projet master
79 23 Redmine Admin
</pre>
80 23 Redmine Admin
81 23 Redmine Admin
h1. Récupérer un projet existant.
82 24 Redmine Admin
83 14 Klaas TJEBBES
<pre>
84 1 Redmine Admin
git clone http://login@dev-eole.ac-dijon.fr/git/nom_projet
85 14 Klaas TJEBBES
</pre>
86 14 Klaas TJEBBES
Cela va créer un répertoire @nom_projet@ contenant un répertoire @.git@.
87 1 Redmine Admin
88 1 Redmine Admin
* Ajouter/retirer des fichiers :
89 1 Redmine Admin
<pre>
90 1 Redmine Admin
git add file1 file2 ...
91 1 Redmine Admin
git remove file1 file2 ...
92 1 Redmine Admin
</pre>
93 1 Redmine Admin
94 14 Klaas TJEBBES
* Pour savoir quel est l'état des modifications :
95 1 Redmine Admin
<pre>
96 1 Redmine Admin
git status
97 1 Redmine Admin
</pre>
98 1 Redmine Admin
99 14 Klaas TJEBBES
* Enregistrer les modifications localement :
100 1 Redmine Admin
<pre>
101 1 Redmine Admin
git commit -a -m"premiere version avec le scm git"
102 1 Redmine Admin
</pre>
103 1 Redmine Admin
104 1 Redmine Admin
* Enregistrer les changements sur le serveur : 
105 1 Redmine Admin
<pre>
106 14 Klaas TJEBBES
git push
107 1 Redmine Admin
</pre>
108 14 Klaas TJEBBES
109 1 Redmine Admin
*remarque* : Avant d'enregistrer les changements sur le serveur, pensez à éditer vos messages de commit, il est possible de les fusionner (Voir "Messages de commit").
110 1 Redmine Admin
111 14 Klaas TJEBBES
* Récupérer les modifications du serveur et les fusionner localement :
112 1 Redmine Admin
<pre>
113 14 Klaas TJEBBES
git pull
114 1 Redmine Admin
</pre>
115 1 Redmine Admin
116 1 Redmine Admin
117 14 Klaas TJEBBES
Notre serveur GIT a plusieurs branches "branch".
118 14 Klaas TJEBBES
* Pour afficher les branches disponibles sur le serveur :
119 14 Klaas TJEBBES
<pre>
120 14 Klaas TJEBBES
git branch -a
121 14 Klaas TJEBBES
</pre>
122 14 Klaas TJEBBES
123 14 Klaas TJEBBES
* Pour paramétrer la prise en compte d'une branche :
124 14 Klaas TJEBBES
<pre>
125 14 Klaas TJEBBES
git config branch.2.2.remote origin
126 14 Klaas TJEBBES
git config branch.2.2.merge refs/heads/2.2
127 14 Klaas TJEBBES
</pre>
128 14 Klaas TJEBBES
129 14 Klaas TJEBBES
* Pour récupérer la branche localement (à ne faire que la première fois) :
130 14 Klaas TJEBBES
<pre>
131 14 Klaas TJEBBES
git fetch origin 2.2:2.2
132 14 Klaas TJEBBES
</pre>
133 14 Klaas TJEBBES
134 14 Klaas TJEBBES
* Pour se placer dans la branche :
135 14 Klaas TJEBBES
<pre>
136 14 Klaas TJEBBES
git checkout 2.2
137 14 Klaas TJEBBES
</pre>
138 14 Klaas TJEBBES
139 1 Redmine Admin
* Récupérer les modifications du serveur :
140 1 Redmine Admin
<pre>
141 1 Redmine Admin
git pull
142 14 Klaas TJEBBES
</pre>
143 14 Klaas TJEBBES
144 14 Klaas TJEBBES
* Pour se placer dans une autre branche, "master" par exemple :
145 14 Klaas TJEBBES
<pre>
146 14 Klaas TJEBBES
git checkout master
147 1 Redmine Admin
</pre>
148 1 Redmine Admin
149 1 Redmine Admin
150 1 Redmine Admin
h1. Branch
151 1 Redmine Admin
152 17 Gérald Schwartzmann
 * Récupérer une branche
153 1 Redmine Admin
<pre>
154 17 Gérald Schwartzmann
git checkout nomDeBrancheExistant
155 17 Gérald Schwartzmann
</pre>
156 17 Gérald Schwartzmann
157 17 Gérald Schwartzmann
 * Créer une branche
158 17 Gérald Schwartzmann
Se placer dans la branche que l'on veut copier
159 17 Gérald Schwartzmann
<pre>
160 17 Gérald Schwartzmann
git checkout maBrancheABrancher
161 17 Gérald Schwartzmann
...
162 17 Gérald Schwartzmann
git checkout -b maNouvelleBranche
163 1 Redmine Admin
</pre>
164 1 Redmine Admin
165 1 Redmine Admin
 * Ceci peut être décomposé en 2 commandes :
166 1 Redmine Admin
<pre>
167 1 Redmine Admin
git branch mabranche
168 1 Redmine Admin
git checkout mabranche
169 1 Redmine Admin
</pre>
170 1 Redmine Admin
171 1 Redmine Admin
 * Diffuser la branche sur le serveur
172 1 Redmine Admin
<pre>
173 1 Redmine Admin
git http-push http://user@194.167.18.22/git/eolebase mabranche
174 13 Joël Cuissinat
</pre>
175 25 Joël Cuissinat
ou, plus simplement :
176 25 Joël Cuissinat
<pre>
177 25 Joël Cuissinat
git push --all
178 25 Joël Cuissinat
</pre>
179 13 Joël Cuissinat
180 13 Joël Cuissinat
* Créer une branche à partir d'un numéro de commit
181 13 Joël Cuissinat
<pre>
182 13 Joël Cuissinat
git checkout -b mabranche <numero_de_commit>
183 5 Emmanuel GARETTE
</pre>
184 5 Emmanuel GARETTE
185 1 Redmine Admin
* Supprimer une branche :
186 1 Redmine Admin
<pre>
187 1 Redmine Admin
git branch -D [nom-branche]
188 1 Redmine Admin
</pre>
189 1 Redmine Admin
190 16 Gaston TJEBBES
* Supprimer une branche sur le dépôt origin
191 16 Gaston TJEBBES
<pre>
192 16 Gaston TJEBBES
git push origin :branche
193 16 Gaston TJEBBES
</pre>
194 16 Gaston TJEBBES
Cela correspond en fait à cette commande là : git push REMOTENAME LOCALBRANCHNAME:REMOTEBRANCHNAME sauf que LOCALBRANCHNAME est vide dans notre exemple.
195 16 Gaston TJEBBES
196 16 Gaston TJEBBES
197 1 Redmine Admin
* Voir les différences entre deux branches
198 1 Redmine Admin
(par exemple avant de merger) : 
199 1 Redmine Admin
<pre>
200 1 Redmine Admin
git diff-tree -p [nom-de-branche]
201 1 Redmine Admin
</pre>
202 1 Redmine Admin
203 1 Redmine Admin
* Pour changer de branche :
204 1 Redmine Admin
<pre>
205 1 Redmine Admin
git checkout autrebranche
206 1 Redmine Admin
</pre>
207 1 Redmine Admin
208 1 Redmine Admin
* Pour revenir à la branche principale :
209 1 Redmine Admin
<pre>
210 1 Redmine Admin
git checkout master
211 1 Redmine Admin
</pre>
212 1 Redmine Admin
213 1 Redmine Admin
* Une autre technique consiste à organiser localement une arborescence différente par branche :
214 1 Redmine Admin
<pre>
215 1 Redmine Admin
git/master
216 1 Redmine Admin
   /mabranche
217 1 Redmine Admin
</pre>
218 1 Redmine Admin
219 1 Redmine Admin
* Savoir dans quelle branche on se trouve :
220 1 Redmine Admin
<pre>
221 1 Redmine Admin
git branch
222 1 Redmine Admin
</pre>
223 1 Redmine Admin
224 1 Redmine Admin
* Voir la branche courante avec le dernier log :
225 1 Redmine Admin
<pre>
226 1 Redmine Admin
git show-branch
227 1 Redmine Admin
</pre>
228 1 Redmine Admin
229 8 Gaston TJEBBES
* Envoyer pour la _première fois_ le contenu de la branche courante sur le serveur :
230 8 Gaston TJEBBES
<pre>
231 8 Gaston TJEBBES
git push origin HEAD
232 8 Gaston TJEBBES
</pre>
233 8 Gaston TJEBBES
234 8 Gaston TJEBBES
Arrivé à ce stade il peut être intéressant d'utiliser @git-gui@ (@/usr/lib/git-core/git-gui@) ou @giggle@.
235 8 Gaston TJEBBES
236 8 Gaston TJEBBES
Pour voir l'historique des différentes branches dans @guit-gui@, "@menu>dépôt>Voir l'historique de toutes les branches@"
237 8 Gaston TJEBBES
238 8 Gaston TJEBBES
* Autres commandes de base :
239 8 Gaston TJEBBES
<pre>
240 8 Gaston TJEBBES
git log
241 8 Gaston TJEBBES
git log --pretty=oneline --all
242 8 Gaston TJEBBES
git diff
243 8 Gaston TJEBBES
</pre>
244 8 Gaston TJEBBES
245 8 Gaston TJEBBES
246 7 Gaston TJEBBES
h2. Branches distantes
247 7 Gaston TJEBBES
248 1 Redmine Admin
* Si vous avez déjà cloné le master d'un projet, pour visualiser les branches disponibles :
249 1 Redmine Admin
<pre>
250 1 Redmine Admin
git branch -a
251 1 Redmine Admin
</pre>
252 7 Gaston TJEBBES
devrait renvoyer quelque chose comme ceci :
253 7 Gaston TJEBBES
<pre>
254 1 Redmine Admin
* master
255 1 Redmine Admin
  remotes/origin/2.2
256 1 Redmine Admin
  remotes/origin/HEAD -> origin/master
257 1 Redmine Admin
  remotes/origin/master
258 1 Redmine Admin
  remotes/origin/upstream
259 1 Redmine Admin
</pre>
260 1 Redmine Admin
261 1 Redmine Admin
* Pour récupérer la branche 2.2 :
262 1 Redmine Admin
<pre>
263 11 Gaston TJEBBES
git co 2.2
264 11 Gaston TJEBBES
</pre>
265 11 Gaston TJEBBES
va récupérer la branche 2.2 auprès du serveur origin.
266 11 Gaston TJEBBES
Une autre méthode:
267 11 Gaston TJEBBES
<pre>
268 1 Redmine Admin
git branch --track 2.2 remotes/origin/2.2
269 1 Redmine Admin
</pre>
270 1 Redmine Admin
271 1 Redmine Admin
h1. Merge
272 1 Redmine Admin
273 1 Redmine Admin
Fusion : action consistant à fusionner une branche avec une autre ("mabranche" avec @master@ par exemple)
274 1 Redmine Admin
275 1 Redmine Admin
Exemple : @merge@ de la branche *mabranche* dans la branche *master* 
276 1 Redmine Admin
277 1 Redmine Admin
* Se placer dans la branche @master@ :
278 1 Redmine Admin
<pre>
279 1 Redmine Admin
git checkout master
280 1 Redmine Admin
git merge mabranche
281 18 Gérald Schwartzmann
git push
282 1 Redmine Admin
</pre>
283 1 Redmine Admin
284 1 Redmine Admin
*remarque* : après un @merge@, il n'y a pas de @commit@ à faire, juste @pull@.
285 1 Redmine Admin
286 1 Redmine Admin
Si vous n'êtes pas satisfait du @merge@, il faut revenir en arrière avec un 
287 1 Redmine Admin
<pre>
288 1 Redmine Admin
git reset --hard
289 1 Redmine Admin
</pre>
290 1 Redmine Admin
291 1 Redmine Admin
**Résoudre un conflit de @merge@**
292 1 Redmine Admin
293 1 Redmine Admin
Si lors d'un @merge@ il y a eu un problème du type :
294 1 Redmine Admin
<pre>
295 1 Redmine Admin
Auto-merged file.txt
296 1 Redmine Admin
CONFLICT (content): Merge conflict in file.txt
297 1 Redmine Admin
Automatic merge failed; fix conflicts and then commit the result.
298 1 Redmine Admin
</pre> et que
299 1 Redmine Admin
<pre>
300 1 Redmine Admin
git commit
301 1 Redmine Admin
</pre> répond qu'il reste des fichiers à merger (unresolved merge), *Il n'y a donc pas eu véritablement de commit*
302 1 Redmine Admin
de même qu'un
303 1 Redmine Admin
<pre>
304 1 Redmine Admin
git status
305 1 Redmine Admin
</pre>
306 1 Redmine Admin
307 1 Redmine Admin
Il faut alors éditer le fichier concerné, résoudre le conflit à la main et faire un nouveau un @commit@ :
308 1 Redmine Admin
<pre>
309 1 Redmine Admin
git add [file.txt]
310 1 Redmine Admin
git commit -m"résolution du conflit"
311 1 Redmine Admin
</pre>
312 1 Redmine Admin
313 1 Redmine Admin
* Pour repérer les fichiers qui n'ont pas été fusionné :
314 1 Redmine Admin
<pre>
315 1 Redmine Admin
git ls-files --unmerged
316 1 Redmine Admin
</pre>
317 1 Redmine Admin
318 21 Joël Cuissinat
319 21 Joël Cuissinat
h1. Stash
320 21 Joël Cuissinat
321 21 Joël Cuissinat
*git stash* permet de sauvegarder des modifications locales afin de les appliquer plus tard.
322 21 Joël Cuissinat
323 21 Joël Cuissinat
* Sauvegarde des modifications :
324 21 Joël Cuissinat
<pre>
325 21 Joël Cuissinat
# git stash save "en attente"
326 21 Joël Cuissinat
Saved working directory and index state On master: en attente
327 21 Joël Cuissinat
</pre>
328 21 Joël Cuissinat
* Liste des modifications sauvegardées :
329 21 Joël Cuissinat
<pre>
330 21 Joël Cuissinat
git stash list
331 21 Joël Cuissinat
stash@{0}: On master: en attente
332 21 Joël Cuissinat
</pre>
333 21 Joël Cuissinat
* Revenir à l'état sauvegardé (_stash@{1}_ pour restaurer la 2ème sauvegarde) :
334 21 Joël Cuissinat
<pre>
335 21 Joël Cuissinat
git stash apply [stash@{0}]
336 21 Joël Cuissinat
</pre>
337 21 Joël Cuissinat
* Nettoyer la liste des sauvegarde :
338 21 Joël Cuissinat
<pre>
339 21 Joël Cuissinat
git stash clear
340 21 Joël Cuissinat
</pre>
341 21 Joël Cuissinat
342 21 Joël Cuissinat
343 21 Joël Cuissinat
344 1 Redmine Admin
h1. Message de commit
345 1 Redmine Admin
346 1 Redmine Admin
*IMPORTANT* : ne pas effectuer de modifications sur des commits déjà envoyés sur le serveur origin (le dépot).
347 1 Redmine Admin
348 1 Redmine Admin
Avant d'envoyer vos données sur le serveur, il est possible de modifier/améliorer les messages de commit.
349 1 Redmine Admin
350 1 Redmine Admin
h2. Modifier le dernier message de commit
351 1 Redmine Admin
352 1 Redmine Admin
<pre>
353 1 Redmine Admin
git commit --amend
354 1 Redmine Admin
</pre>
355 1 Redmine Admin
Modifier, sauvegarder et quitter.
356 1 Redmine Admin
357 1 Redmine Admin
h2. Modifier les trois derniers messages
358 1 Redmine Admin
359 1 Redmine Admin
* On lance un rebase
360 1 Redmine Admin
<pre>
361 1 Redmine Admin
git rebase -i HEAD~3
362 1 Redmine Admin
</pre>
363 1 Redmine Admin
* Un éditeur de texte s'ouvre avec quelque chose qui ressemble à ça:
364 1 Redmine Admin
<pre>
365 1 Redmine Admin
pick 6ffa65b update des bases de donnees editable=0 et pas 2
366 1 Redmine Admin
pick 9697740 update des bases vers 2.2.3 : nettoyage et ajout d'un __init__.py (ref #11)
367 1 Redmine Admin
pick e56a7a4 Configuration des bases de donnees pour le passage en version 2.2.3 (fixes #11 : fixé)
368 1 Redmine Admin
369 1 Redmine Admin
# Rebase cd9333c..e56a7a4 onto cd9333c
370 1 Redmine Admin
#
371 1 Redmine Admin
# Commands:
372 1 Redmine Admin
#  p, pick = use commit
373 1 Redmine Admin
#  r, reword = use commit, but edit the commit message
374 1 Redmine Admin
#  e, edit = use commit, but stop for amending
375 1 Redmine Admin
#  s, squash = use commit, but meld into previous commit
376 1 Redmine Admin
#
377 1 Redmine Admin
# If you remove a line here THAT COMMIT WILL BE LOST.
378 1 Redmine Admin
# However, if you remove everything, the rebase will be aborted.
379 1 Redmine Admin
#
380 1 Redmine Admin
</pre>
381 1 Redmine Admin
* Changer pick en edit sur les lignes correspondantes aux commit à modifier, par exemple :
382 1 Redmine Admin
<pre>
383 1 Redmine Admin
edit 6ffa65b update des bases de donnees editable=0 et pas 2
384 1 Redmine Admin
pick 9697740 update des bases vers 2.2.3 : nettoyage et ajout d'un __init__.py (ref #11)
385 1 Redmine Admin
pick e56a7a4 Configuration des bases de donnees pour le passage en version 2.2.3 (fixes #11 : fixé)
386 1 Redmine Admin
</pre>
387 1 Redmine Admin
* Sauver et quitter.
388 1 Redmine Admin
* Lancer la commande :
389 1 Redmine Admin
<pre>
390 1 Redmine Admin
git commit --amend
391 1 Redmine Admin
</pre>
392 1 Redmine Admin
* Modifier les messages de commit, par ex :
393 1 Redmine Admin
<pre>
394 1 Redmine Admin
update des bases de donnees editable=0 et pas 2 (ref #11)
395 1 Redmine Admin
</pre> 
396 1 Redmine Admin
* Sauvegarder et quitter
397 1 Redmine Admin
* Lancer la commande :
398 1 Redmine Admin
<pre>
399 1 Redmine Admin
git rebase --continue
400 1 Redmine Admin
</pre>
401 1 Redmine Admin
* Vérifier les messages de commit
402 1 Redmine Admin
<pre>
403 1 Redmine Admin
git log
404 1 Redmine Admin
</pre>
405 1 Redmine Admin
406 1 Redmine Admin
407 1 Redmine Admin
h2. Fusionner des commits
408 1 Redmine Admin
409 1 Redmine Admin
Il est possible de fusionner des commit afin d'éviter des commits multiples pour des modifications mineures.
410 1 Redmine Admin
* Lancer un git rebase
411 1 Redmine Admin
<pre>
412 1 Redmine Admin
git rebase -i HEAD~3
413 1 Redmine Admin
</pre>
414 1 Redmine Admin
<pre>
415 1 Redmine Admin
pick 16098ec Ajout d'icône gepi et cdt (ref #51)
416 1 Redmine Admin
pick f244e89 Deplacement d'icone
417 1 Redmine Admin
pick 7c8670c Deplacement des icones sources
418 1 Redmine Admin
419 1 Redmine Admin
# Rebase 5f5bfee..7c8670c onto 5f5bfee
420 1 Redmine Admin
#
421 1 Redmine Admin
# Commands:
422 1 Redmine Admin
#  p, pick = use commit
423 1 Redmine Admin
#  r, reword = use commit, but edit the commit message
424 1 Redmine Admin
#  e, edit = use commit, but stop for amending
425 1 Redmine Admin
#  s, squash = use commit, but meld into previous commit
426 1 Redmine Admin
#
427 1 Redmine Admin
# If you remove a line here THAT COMMIT WILL BE LOST.
428 1 Redmine Admin
# However, if you remove everything, the rebase will be aborted.
429 1 Redmine Admin
#
430 1 Redmine Admin
</pre>
431 1 Redmine Admin
432 1 Redmine Admin
* Changer pick en squash fusionne votre commit avec la ligne au-dessus
433 1 Redmine Admin
<pre>
434 1 Redmine Admin
pick 16098ec Ajout d'icône gepi et cdt (ref #51)
435 1 Redmine Admin
squash f244e89 Deplacement d'icone
436 1 Redmine Admin
squash 7c8670c Deplacement des icones sources
437 1 Redmine Admin
</pre>
438 1 Redmine Admin
* Sauver et quitter, Un éditeur s'ouvre:
439 1 Redmine Admin
<pre>
440 1 Redmine Admin
# This is a combination of 3 commits.
441 1 Redmine Admin
# The first commit's message is:
442 1 Redmine Admin
Ajout d'icône gepi et cdt (ref #51)
443 1 Redmine Admin
444 1 Redmine Admin
# This is the 2nd commit message:
445 1 Redmine Admin
446 1 Redmine Admin
Deplacement d'icone
447 1 Redmine Admin
448 1 Redmine Admin
# This is the 3rd commit message:
449 1 Redmine Admin
450 1 Redmine Admin
Deplacement des icones sources
451 1 Redmine Admin
452 1 Redmine Admin
# Please enter the commit message for your changes. Lines starting
453 1 Redmine Admin
# with '#' will be ignored, and an empty message aborts the commit.
454 1 Redmine Admin
# Not currently on any branch.
455 1 Redmine Admin
# Changes to be committed:
456 1 Redmine Admin
#   (use "git reset HEAD <file>..." to unstage)
457 1 Redmine Admin
#
458 1 Redmine Admin
#       modified:   eole/tmpls/update_creole_posh.sql
459 1 Redmine Admin
#       renamed:    plugins/plugin_desktop/icones/old/Corbeille.png -> plugins/plugin_desktop/icones/Corbeille.png
460 1 Redmine Admin
#       renamed:    plugins/plugin_desktop/icones/old/Courrier.png -> plugins/plugin_desktop/icones/Courrier.png
461 1 Redmine Admin
#       renamed:    plugins/plugin_desktop/icones/old/agenda.png -> plugins/plugin_desktop/icones/agenda.png
462 1 Redmine Admin
#       new file:   plugins/plugin_desktop/icones/cdt.png
463 1 Redmine Admin
#       modified:   plugins/plugin_desktop/icones/dir.png
464 1 Redmine Admin
#       modified:   plugins/plugin_desktop/icones/gepi.png
465 1 Redmine Admin
#       renamed:    plugins/plugin_desktop/icones/old/mail.jpg -> plugins/plugin_desktop/icones/mail.jpg
466 1 Redmine Admin
#       modified:   plugins/plugin_desktop/icones/mail.png
467 1 Redmine Admin
#       new file:   sources-desktop/icones/cdt.xcf
468 1 Redmine Admin
#       renamed:    plugins/plugin_desktop/icones/grand/moodle.gif -> sources-desktop/icones/moodle.gif
469 1 Redmine Admin
#
470 1 Redmine Admin
# Untracked files:
471 20 Joël Cuissinat
#   (use "git add <file>..." to include in what will be committed)
472 19 Joël Cuissinat
#
473 19 Joël Cuissinat
#       databases/bdd/scribe-posh.sql.sav
474 19 Joël Cuissinat
</pre>
475 19 Joël Cuissinat
* Éditer les messages (un message suffit)
476 19 Joël Cuissinat
<pre>
477 19 Joël Cuissinat
# The first commit's message is:
478 19 Joël Cuissinat
Ajout d'icône pour les applications scribe (ref #51)
479 19 Joël Cuissinat
# This is the 2nd commit message:
480 19 Joël Cuissinat
481 19 Joël Cuissinat
# This is the 3rd commit message:
482 19 Joël Cuissinat
483 19 Joël Cuissinat
# Please enter the commit message for your changes. Lines starting
484 19 Joël Cuissinat
</pre>
485 19 Joël Cuissinat
* Sauver et quitter
486 19 Joël Cuissinat
* Vérifier que cela ressemble bien à ce que vous voulez
487 19 Joël Cuissinat
<pre>
488 19 Joël Cuissinat
git log
489 19 Joël Cuissinat
</pre>
490 19 Joël Cuissinat
491 26 Emmanuel GARETTE
h2. Suppression d'un commit
492 19 Joël Cuissinat
493 26 Emmanuel GARETTE
git rebase --onto ANCIENIDCOMMIT NOUVEAUIDCOMMIT
494 19 Joël Cuissinat
495 1 Redmine Admin
h1. Trucs et astuces
496 1 Redmine Admin
497 1 Redmine Admin
* Résoudre un signalement avec l'ajout de "fixes #<numéro du signalement>"
498 1 Redmine Admin
<pre>
499 1 Redmine Admin
git commit -m"La nouvelle feature fixes #<numéro du signalement>"
500 1 Redmine Admin
git http-push ....
501 1 Redmine Admin
</pre>
502 1 Redmine Admin
503 1 Redmine Admin
* Faire référence à un signalement
504 1 Redmine Admin
<pre>
505 1 Redmine Admin
git commit -m"bla bla bal du bug #<numéro du signalement>"
506 1 Redmine Admin
</pre>
507 1 Redmine Admin
508 1 Redmine Admin
* Activer la coloration syntaxique 
509 1 Redmine Admin
<pre>
510 1 Redmine Admin
git config --global color.ui true
511 1 Redmine Admin
</pre>
512 1 Redmine Admin
513 1 Redmine Admin
* Pour controler les fichiers à ne JAMAIS prendre en compte (@commit@), utiliser le fichier @~/.gitignore@. Exemple d'un fichier @~/.gitignore@ :
514 1 Redmine Admin
<pre>
515 1 Redmine Admin
# ignorer le fichier lui même
516 1 Redmine Admin
.gitignore
517 1 Redmine Admin
# les fichiers de sauvegarde VIM
518 1 Redmine Admin
*~
519 1 Redmine Admin
# ignorer les fichiers html générés
520 1 Redmine Admin
*.html
521 1 Redmine Admin
# sauf mon_fichier.html que je veux prendre en compte
522 1 Redmine Admin
!mon_fichier.html
523 1 Redmine Admin
# ignorer les dossiers @.svn@
524 1 Redmine Admin
.svn
525 1 Redmine Admin
# ignore documentation buid html files
526 1 Redmine Admin
.build
527 1 Redmine Admin
</pre>
528 1 Redmine Admin
529 1 Redmine Admin
* Le fichier @~/.gitconfig@ peut permettre d'éviter de taper trop au clavier :
530 1 Redmine Admin
<pre>
531 1 Redmine Admin
[alias]
532 1 Redmine Admin
      st = status
533 1 Redmine Admin
      di = diff
534 1 Redmine Admin
      co = checkout
535 1 Redmine Admin
      ci = commit
536 1 Redmine Admin
      br = branch
537 1 Redmine Admin
      sta = stash
538 1 Redmine Admin
</pre>
539 1 Redmine Admin
540 1 Redmine Admin
* Pour éviter de taper l'URL et son mot de passe à chaque @push@ et @pull@, il faut :
541 1 Redmine Admin
542 1 Redmine Admin
 * configurer l'URL du projet
543 1 Redmine Admin
<pre>
544 1 Redmine Admin
git config remote.origin.url http://194.167.18.22/git/projet/
545 1 Redmine Admin
git config remote.origin.mirror false
546 1 Redmine Admin
</pre>
547 1 Redmine Admin
 * renseigner le fichier @~/.netrc@ :
548 1 Redmine Admin
<pre>
549 2 samuel morin
machine dev-eole.ac-dijon.fr
550 1 Redmine Admin
login monlogin
551 1 Redmine Admin
password monmotdepasse
552 1 Redmine Admin
</pre>
553 1 Redmine Admin
 * paramétrer les droits du fichier @~/.netrc@ :
554 1 Redmine Admin
<pre>
555 1 Redmine Admin
chmod 600 ~/.netrc
556 1 Redmine Admin
</pre>
557 1 Redmine Admin
Ensuite @git push@ et @git pull@ ne posent plus de questions.
558 1 Redmine Admin
559 1 Redmine Admin
560 1 Redmine Admin
* Pour faire le ménage :
561 1 Redmine Admin
<pre>
562 1 Redmine Admin
git repack
563 1 Redmine Admin
git prune
564 1 Redmine Admin
</pre>
565 1 Redmine Admin
566 1 Redmine Admin
* Pour repérer des @commit@ dans des branches qui n'ont pas été fusionnés (@merge@) dans la branche principale :
567 1 Redmine Admin
* Pour voir les @commit@ dans la branche *ma_branche* qui n'ont pas été fusionnés (@merge@) dans *master* : 
568 1 Redmine Admin
<pre>
569 1 Redmine Admin
git cherry -v master ma_branche
570 1 Redmine Admin
</pre>
571 1 Redmine Admin
572 1 Redmine Admin
h1. De subversion vers git
573 1 Redmine Admin
574 1 Redmine Admin
Il n'existe pas de commande *@update@*. Lorsqu'un fichier a été modifié localement par erreur et qu'on veut récupérer l'original, les habitudes étaient :
575 1 Redmine Admin
<pre>
576 1 Redmine Admin
rm mon_fichier
577 1 Redmine Admin
svn update
578 1 Redmine Admin
</pre>
579 1 Redmine Admin
580 1 Redmine Admin
A la place, il faut faire
581 1 Redmine Admin
<pre>
582 1 Redmine Admin
git checkout mon_fichier
583 1 Redmine Admin
</pre>
584 1 Redmine Admin
585 1 Redmine Admin
Pour revenir à un checkout frais dans le projet entier, utiliser *@reset@*. On peut annuler un commit en faisant :
586 1 Redmine Admin
587 1 Redmine Admin
<pre>
588 1 Redmine Admin
git reset --hard HEAD
589 1 Redmine Admin
</pre>
590 1 Redmine Admin
591 1 Redmine Admin
h1. Créer un patch et l'intégrer
592 1 Redmine Admin
593 1 Redmine Admin
Dans un projet (Ex.: conf-horus) on a créé une branche "ma_branche" dans laquelle on a fait des modifications (par rapport à "master").
594 1 Redmine Admin
595 1 Redmine Admin
On veut récupérer un fichier recensant les différences entre la branche *master* et la branche *ma_branche* (un fichier @diff@) :
596 1 Redmine Admin
<pre>
597 1 Redmine Admin
git diff master [nom-de-branche]  > file.patch
598 1 Redmine Admin
</pre>
599 1 Redmine Admin
600 1 Redmine Admin
* Une fois le patch récupéré, pour l'inclure dans la branche *master* :
601 1 Redmine Admin
602 1 Redmine Admin
<pre>
603 1 Redmine Admin
git apply --stat file.patch
604 1 Redmine Admin
git apply --check file.patch
605 10 Gaston TJEBBES
</pre> permet de tester le patch, et :
606 1 Redmine Admin
<pre>
607 1 Redmine Admin
git apply file.patch
608 1 Redmine Admin
</pre> permet de l'appliquer
609 9 Gaston TJEBBES
610 9 Gaston TJEBBES
h1. Tags
611 9 Gaston TJEBBES
612 9 Gaston TJEBBES
613 9 Gaston TJEBBES
*git* fait une différence entre les branches et les tags, cela se voit bien avec *git-gui* (vue de l'historique des branches).
614 9 Gaston TJEBBES
615 9 Gaston TJEBBES
Une branche est modifiable, un tag ne l'est pas. 
616 9 Gaston TJEBBES
617 9 Gaston TJEBBES
* Création du @tag@ :
618 9 Gaston TJEBBES
<pre>
619 9 Gaston TJEBBES
git tag mon-premier-tag
620 9 Gaston TJEBBES
</pre>
621 9 Gaston TJEBBES
622 9 Gaston TJEBBES
* Liste des tags :
623 9 Gaston TJEBBES
<pre>
624 9 Gaston TJEBBES
git tag
625 9 Gaston TJEBBES
</pre>
626 9 Gaston TJEBBES
627 9 Gaston TJEBBES
* Commit d'un @tag@ :
628 9 Gaston TJEBBES
<pre>
629 9 Gaston TJEBBES
git push --tags http://login@dev-eole.ac-dijon.fr/git/sandbox
630 9 Gaston TJEBBES
</pre>
631 9 Gaston TJEBBES
632 9 Gaston TJEBBES
 * ou bien :
633 9 Gaston TJEBBES
<pre>
634 9 Gaston TJEBBES
git push http://login@dev-eole.ac-dijon.fr/git/sandbox <nom_tag>
635 9 Gaston TJEBBES
</pre>
636 9 Gaston TJEBBES
637 9 Gaston TJEBBES
 * ou encore :
638 9 Gaston TJEBBES
<pre>
639 9 Gaston TJEBBES
git push http://login@dev-eole.ac-dijon.fr/git/sandbox <nom_branche> <nom_tag>
640 9 Gaston TJEBBES
</pre>
641 9 Gaston TJEBBES
642 9 Gaston TJEBBES
* Recupérer un @tag@ :
643 9 Gaston TJEBBES
<pre>
644 9 Gaston TJEBBES
git checkout tags/<nom_tag>
645 9 Gaston TJEBBES
</pre>
646 9 Gaston TJEBBES
647 9 Gaston TJEBBES
* Pour voir quel @commit@ exactement a été taggé :
648 9 Gaston TJEBBES
<pre>
649 9 Gaston TJEBBES
git show <nom_tag>
650 9 Gaston TJEBBES
</pre>