Mon blog sur l'artisanat logiciel et l'Agilité

Software Craftmanship - Agile (fork from My Octopress Blog)

Mémo GIT (2nd Partie)

GIT

Ce post est plutôt un mémo pour mon usage personnel, mais s'il peut aider quelqu'un j'en serai ravi :). Voilà donc un mémo traitant des problématiques ou cas d'utilisation que j'ai rencontré. Pour mémoire, je rappelle que je suis dans un environnement SVN (centralisé) - GIT (en client sur mon poste).

Cas d'utilisation

Switch d'une branche SVN

Jusqu'à présent nous étions sur le ‘master’ côtès Git et en remote nous pointions sur ‘origin/trunk’, sur SVN il y a eu un problème en PROD et donc la nécessité de faire un patch dans une branche. La branche a été créée côtès SVN mais n'est pas visible avec Git:

1
2
3
4
5
6
$ git branch -r
  origin/V3.11_MAINT
  origin/V3.12_MAINT
  origin/tags/V3.11.1
  origin/tags/V3.12_Liv1
  origin/trunk

Il faut synchroniser

1
2
3
4
5
6
7
8
9
$ git svn fetch
blablabla assez long ...
 git branch -r
  origin/V3.11_MAINT
  origin/V3.12_MAINT
  origin/V3.13_MAINT
  origin/tags/V3.11.1
  origin/tags/V3.12_Liv1
  origin/trunk

et la magie la branche V3.13_MAINT apparait. Maintenant nous somme toujours sur le trunk en local:

1
2
3
4
5
6
7
8
9
10
11
$ git svn info
Path: .
URL: https://monserveur:8443/svn/MON_PROJET/trunk
Repository Root: https://monserveur:8443/svn/MON_PROJET
Repository UUID: 2a9a025e-1ade-4945-b3f3-c86421e8e34f
Revision: 2813
Node Kind: directory
Schedule: normal
Last Changed Author: m_lap
Last Changed Rev: 2813
Last Changed Date: 2017-04-18 11:32:21 +0200 (mar., 18 avr. 2017)

Il nous reste plus qu'a créé un branche dont l'origine est cette branche

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ git branch maint remotes/origin/V3.13_MAINT
$ git branch
  maint
* master
$ git checkout maint
Switched to branch 'maint'
$ git svn info
Path: .
URL: https://monserveur:8443/svn/MON_PROJET/branches/V3.13_MAINT
Repository Root: https://monserveur:8443/svn/MON_PROJET
Repository UUID: 2a9a025e-1ade-4945-b3f3-c86421e8e34f
Revision: 2814
Node Kind: directory
Schedule: normal
Last Changed Author: p_che
Last Changed Rev: 2808
Last Changed Date: 2017-04-12 15:20:33 +0200 (mer., 12 avr. 2017)

Et nous pouvons retouver notre flux de travail habituel! \o/

Erreur

  • Au cours de mes devs j'ai oublié parfois d'ajouter une modification, un paramètre … un dernier petit détails, pour y remédier je fais:
    git commit --ammend
  • Puis une fois terminé je pousse sur SVN git svn dcommit
  • Et puis un jour dans ma lancé, je refais un git commit --ammmend sur un commit déjà poussé sur SVN, il faut donc faire un roolback et un nouveau commit puis pousser, soit:
1
2
3
4
git reflog
git reset --soft HEAD@{1}
git commit -C HEAD@{1}
git svn dcommit
  • Dans la folie du commit avec ammend , j'ai aussi essayé un revert qui m'a mis dans cette position : HEAD/master, et origin/trunk décalé alors que je voulais garder la version d'origine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ git log --all --graph --color --name-status --format='%C(yellow)%h%Creset %cr %C(blue)%cn%Creset -%C(auto)%d%Creset %s'
 * 95c473c 27 hours ago j_pal - (HEAD -> master) A second fix
|
| M     PROJECT/Fixes/Restore/restore.ksh
| M     PROJECT/Fixes/Restore/README.txt
* 95c473c 27 hours ago j_pal - (origin/trunk) My Fix 
|
| M     PROJECT/Fixes/Restore/restore.ksh
| M     PROJECT/Fixes/Restore/README.txt
* ed5f1f3 2 days ago j_pal - Restore script
|
| A     PROJECT/Fixes/Restore/restore.ksh
| A     PROJECT/Fixes/Restore/README.txt
|
...
  • Il fallait donc revenir à un commit ou Head, master et origin pointé sur le même commit:
1
git reset --hard origin/trunk

Questions

Pourquoi git remote -v ne me renvoie rien?

  • Je ne sais si vous savez contacter moi…

/!\ REGLES A RESPECTER - RAPPEL

  • git svn NE PAS partager/interrargir avec un autre repo git, toujours repasser par le repo SVN
  • Garder son historique le plus linéaire possible (rebase est ton ami)

Liens et sources