linux:memo_git
Différences
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 | ||
| linux:memo_git [04/08/2011 18:27] – màj liens daniel | linux:memo_git [21/12/2012 11:23] (Version actuelle) – aj qq Commandes courantes daniel | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| Git est un gestionnaire de versions (comme svn, cvs ou d' | Git est un gestionnaire de versions (comme svn, cvs ou d' | ||
| - | Un résumé | + | Un bon résumé |
| - | Mais, parfois, la centralisation | + | Avant de se lancer, il vaut mieux lire au moins les chapitres 1 et 2 du livre pro git http:// |
| + | * workspace : le répertoire courant, changer de branche revient à faire un échange de snapshots de ce répertoire (ou d'une partie), pas à en changer (par opposition à svn où on passe de trunk à branche/ | ||
| + | * index (ou stage) : la liste de ce qui se passera au prochain commit. Contrairement à svn on peut faire un commit de plusieurs fichiers, mais pas forcément dans leur état courant, on commit l' | ||
| + | * local repository : la base git locale (qui contient tout l' | ||
| + | * remote repository : un dépôt distant, il peut y en avoir plein, et on peut avoir des branches qui pointent vers différents dépôt. | ||
| + | * stash : ça on peut s'en passer dans un 1er temps, même si c'est pratique. C'est un espace " | ||
| + | |||
| + | Résumé des commandes git | ||
| + | * graphique interactif efficace : http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * chez [[http:// | ||
| + | |||
| + | La référence (les pages man) : http:// | ||
| + | |||
| + | Il y a aussi le [[http:// | ||
| + | |||
| + | Des alias intéressant sur https:// | ||
| + | |||
| + | La page de doc du plugin netbeans http:// | ||
| + | |||
| + | Tip & tricks | ||
| + | * http:// | ||
| + | |||
| + | ===== Commandes courantes ===== | ||
| + | * Modifier le dernier message de commit '' | ||
| + | * voir les serveurs distants (ajouter -v pour avoir les urls) '' | ||
| + | * editer la conf par defaut '' | ||
| + | |||
| + | ===== Dépôt centralisateur ===== | ||
| + | |||
| + | Le décentralisé c'est très bien, mais parfois un dépôt qui centralise est bien pratique, et c'est aussi possible. | ||
| Cf http:// | Cf http:// | ||
| Ligne 11: | Ligne 43: | ||
| Ensuite, quelques liens utiles | Ensuite, quelques liens utiles | ||
| * http:// | * http:// | ||
| - | * http:// | ||
| - | * http:// | ||
| * http:// | * http:// | ||
| * http:// | * http:// | ||
| Ligne 20: | Ligne 50: | ||
| * http:// | * http:// | ||
| - | ===== Opérations courantes ===== | + | Ce qui suit est assez ancien et à prendre avec des pincettes |
| - | http:// | + | |
| - | <code bash> | + | |
| - | # transformer le dossier courant en projet git | + | |
| - | git init | + | |
| - | # ajouter tous ses fichiers au projet (ou bien préciser les fichiers | + | |
| - | git add . | + | |
| - | # ajouter un alias pour un projet sur un serveur distant | + | |
| - | git remote add alias_de_ce_projet_sur_ce_serveur user@< | + | |
| - | # y envoyer les fichiers | + | |
| - | git push alias_de_ce_projet_sur_ce_serveur la_branche # " | + | |
| - | + | ||
| - | # commit d`un fichier | + | |
| - | git commit -m 'message de commit' | + | |
| - | # commit de tous les fichiers (localement) | + | |
| - | git commit -m ' | + | |
| - | # envoi de tous les derniers commit (depuis le dernier push) sur le serveur | + | |
| - | git push | + | |
| - | </ | + | |
| ==== Ajout d'un dépôt local sur le serveur ==== | ==== Ajout d'un dépôt local sur le serveur ==== | ||
| Ligne 74: | Ligne 85: | ||
| </ | </ | ||
| - | ===== Script de démarrage ===== | ||
| - | Mon script d'init / | ||
| - | <code bash> | ||
| - | #!/bin/sh | ||
| - | ### BEGIN INIT INFO | ||
| - | # Provides: | ||
| - | # Required-Start: | ||
| - | # Required-Stop: | ||
| - | # Default-Start: | ||
| - | # Default-Stop: | ||
| - | # Short-Description: | ||
| - | # Description: | ||
| - | ### END INIT INFO | ||
| - | # Author: Daniel Caillibaud < | ||
| - | PATH=/ | + | ==== Script de démarrage ==== |
| - | DESC="git-daemon (which handles git protocol on 9418 port)" | + | Avant le paquet |
| - | NAME=git-daemon | + | <code bash> |
| - | DAEMON=/usr/bin/$NAME | + | aptitude install |
| - | # DAEMON_ARGS later (after default conf load) | + | ln -s /usr/bin/sv /etc/init.d/ |
| - | PIDFILE=/var/run/$NAME.pid | + | # et on va modifier |
| - | SCRIPTNAME=/etc/init.d/$NAME | + | </code> |
| - | # start-stop-daemon options | + | ===== Exemples ===== |
| - | SSD_OPTIONS=' | + | Ci dessous qq démos, pour vous faire une idée. |
| - | # Exit if the package is not installed | + | Les ligne qui commencent par "#>" |
| - | [ ! -x "$DAEMON" | + | |
| - | # Read configuration variable file if it is present | ||
| - | [ -r / | ||
| - | DAEMON_ARGS=" | ||
| - | # Load the VERBOSE setting and other rcS variables | + | ==== Un local, plusieurs distants ==== |
| - | . / | + | |
| - | # Define LSB log_* functions. | + | J' |
| - | # Depend on lsb-base | + | |
| - | . / | + | |
| - | # | + | Voici ce que j'ai fait (un seul serveur ici, mais si ça marche pour A...) |
| - | # Function that starts the daemon/ | + | |
| - | # | + | |
| - | do_start() | + | |
| - | { | + | |
| - | # Return | + | |
| - | # 0 if daemon has been started | + | |
| - | # 1 if daemon was already running | + | |
| - | # 2 if daemon could not be started | + | |
| - | start-stop-daemon $SSD_OPTIONS --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ | + | |
| - | || return 1 | + | |
| - | start-stop-daemon $SSD_OPTIONS --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ | + | |
| - | $DAEMON_ARGS \ | + | |
| - | || return 2 | + | |
| - | } | + | |
| - | + | ||
| - | # | + | |
| - | # Function that stops the daemon/ | + | |
| - | # | + | |
| - | do_stop() | + | |
| - | { | + | |
| - | # Return | + | |
| - | # 0 if daemon has been stopped | + | |
| - | # 1 if daemon was already stopped | + | |
| - | # 2 if daemon could not be stopped | + | |
| - | # other if a failure occurred | + | |
| - | start-stop-daemon --stop --quiet --retry=TERM/ | + | |
| - | RETVAL=" | + | |
| - | [ " | + | |
| - | start-stop-daemon --stop --quiet --oknodo --retry=0/ | + | |
| - | [ " | + | |
| - | # Many daemons don't delete their pidfiles when they exit. | + | |
| - | rm -f $PIDFILE | + | |
| - | return " | + | |
| - | } | + | |
| - | + | ||
| - | case " | + | |
| - | start) | + | |
| - | log_daemon_msg " | + | |
| - | do_start | + | |
| - | case " | + | |
| - | 0|1) [ " | + | |
| - | 2) [ " | + | |
| - | esac | + | |
| - | ;; | + | |
| - | stop) | + | |
| - | [ " | + | |
| - | do_stop | + | |
| - | case " | + | |
| - | 0|1) [ " | + | |
| - | 2) [ " | + | |
| - | esac | + | |
| - | ;; | + | |
| - | + | ||
| - | restart) | + | |
| - | log_daemon_msg " | + | |
| - | do_stop | + | |
| - | case " | + | |
| - | 0|1) | + | |
| - | do_start | + | |
| - | case " | + | |
| - | 0) log_end_msg 0 ;; | + | |
| - | 1) log_end_msg 1 ;; # Old process is still running | + | |
| - | *) log_end_msg 1 ;; # Failed to start | + | |
| - | esac | + | |
| - | ;; | + | |
| - | *) | + | |
| - | # Failed to stop | + | |
| - | log_end_msg 1 | + | |
| - | ;; | + | |
| - | esac | + | |
| - | ;; | + | |
| - | *) | + | |
| - | echo " | + | |
| - | exit 3 | + | |
| - | ;; | + | |
| - | esac | + | |
| - | </ | + | |
| - | + | ||
| - | Avec les prefs | + | |
| <code bash> | <code bash> | ||
| - | echo ' | + | mkdir serveurA |
| - | </ | + | cd serveurA/ |
| + | h=$(basename $(pwd)); touch $h a c; echo $h > c; | ||
| + | git init --bare | ||
| - | Mais tout ça sert pas à grand chose car il y a un paquet git-daemon-run, | + | # un clones (pour vérifier que le push sur les serveurs est bien ce qui est attendu) |
| - | + | cd .. | |
| - | Bref, ce qui suit va quand même plus vite | + | git clone serveurA cloneA |
| - | <code bash> | + | # et aussi pour le peuplement initial |
| - | aptitude install | + | cd cloneA |
| - | ln -s /usr/bin/sv /etc/init.d/git-daemon | + | h=$(basename $(pwd)); touch $h c1 c2; echo $h > c2; |
| - | # et on va modifier | + | git add . |
| + | git commit | ||
| + | git push origin master | ||
| + | |||
| + | # et un dépôt local | ||
| + | cd .. | ||
| + | mkdir loc | ||
| + | cd loc | ||
| + | git init | ||
| + | # avec qq fichiers | ||
| + | h=$(basename $(pwd)); touch $h c2; echo $h > c2; | ||
| + | git add . | ||
| + | git commit -a -m "1er commit $h" | ||
| + | # ça nous a créé une branche master, mais on veut la nommer autrement pour pas confondre avec ceux des remote | ||
| + | # et éviter | ||
| + | git branch | ||
| + | |||
| + | # un alias pour le serveur | ||
| + | git remote add remoteA ../serveurA master | ||
| + | |||
| + | # une branche que l′on va synchroniser avec le serveur A | ||
| + | git fetch remoteA | ||
| + | git checkout --track -b brancheA remoteA/master # => créé la branche brancheA en lien avec remoteA/master | ||
| + | |||
| + | # on modifie un fichier | ||
| + | echo "mod 1" > cloneA | ||
| + | git commit | ||
| + | # que l′on veut envoyer | ||
| + | git push | ||
| + | #> | ||
| + | # Ah bon ? Le tracking marche pas ? | ||
| + | git push remoteA brancheA: | ||
| + | # ça push mieux | ||
| + | # 2e modif pour voir si ça track mieux maintenant qu′on lui a montré | ||
| + | echo "mod 2" >> cloneA | ||
| + | git commit | ||
| + | git push | ||
| + | # tj rien :-S, et avec -u ? | ||
| + | git push -u remoteA brancheA: | ||
| + | #> [...] | ||
| + | #> To ../ | ||
| + | #> 3b00bff..cb44c59 | ||
| + | #> Branch brancheA set up to track remote branch master from remoteA. | ||
| + | # ça parait pourtant clair, mais | ||
| + | echo "mod 3" >> cloneA | ||
| + | git commit -a -m "mod 3" | ||
| + | git push | ||
| + | #> Everything up-to-date | ||
| + | # pas mieux... | ||
| </ | </ | ||
| - | |||
linux/memo_git.1312475237.txt.gz · Dernière modification : 04/08/2011 18:27 de daniel