developpement:git

GIT

Git est un gestionnaire de version décentralisé comme GNU Arch ou Monotone (ou Bitkeeper dans le monde propriétaire). Chaque répertoire de travail est un vrai dépôt git (avec toutes les fonctionnalités), il ne dépend pas du réseau et donc d'un serveur centrale.

  • Systeme libre avec peu de contraintes
  • Gestionnaire de source et de configuration distribué
  • On commit en local avant de faire un push sur le repo central ou vers un collègue …
  • Création d'un snapshot de tout le projet (% svn qui fait un delta entre les états)
  • Il y a un historique de l'état de tous les commits
  • On fait toujours référence au pointeur parent
  • Très rapide pour les actions

Avantage d'un hub:

  • Dernière version partagé
  • Backup distant

Inconvénients:

  • Dépendance unique

wiki.debian.org

# installation
$ aptitude install git-core gitweb 
 
# création d'un utilisateur pour le repo distant
$ adduser git
# sécurisation de l'acces ssh en modifiant le sh
$ which git-shell
$ nano /etc/passwd
# mettre à jour la ligne git:x:1000:1000::/home/git:/usr/bin/git-shell 
 
# initialiser le repo
$ cd /opt/git
$ mkdir test.git
$ cd test.git
$ git --bare init
 
 
# configuration de gitweb
$ mkdir /var/www/git 
$ [ -d "/var/cache/git" ] || sudo mkdir /var/cache/git 
$ nano /etc/apache2/conf.d/git 

Mettre le code suivant dans le fichier:

<Directory /var/www/git>
   Allow from all
   AllowOverride all
   Order allow,deny
   Options ExecCGI
   <Files gitweb.cgi>
   SetHandler cgi-script
   </Files>
</Directory>
DirectoryIndex gitweb.cgi
SetEnv  GITWEB_CONFIG  /etc/gitweb.conf
$ mv /usr/share/gitweb/* /var/www/git 
$ mv /usr/lib/cgi-bin/gitweb.cgi /var/www/git 
$ nano /etc/gitweb.conf 

Mettre à jour le fichier:

$projectroot = '/var/cache/git/';
$git_temp = "/tmp";
#$home_link = $my_uri || "/";
$home_text = "indextext.html";
$projects_list = $projectroot;
$stylesheet = "/git/gitweb.css";
$logo = "/git/git-logo.png";
$favicon = "/git/git-favicon.png";

Source www.howtoforge.com

source 2 git-10-commandes-utiles

Première configurations

$ git config --global user.name "Gwadanina"
$ git config --global user.email "test@gwadanina_net"
$ git config --global core.editor nano
 
 
$ cd mon_project_de_test
$ git init
$ git add .
$ git commit -m 'init'
$ git remote add origin git@gwadanina_net:/home/git/test.git
# accès avec un port ssh personnalisé
$ git remote add origin ssh://git@gwadanina_net:22/home/git/test.git
$ git push origin master
$ nano .bash_profile
# Personnalisation du PS1 à la mode du maître
PS1="\[\e[32m\]\u\[\e[0m\]@\[\e[36m\]\h\[\e[0;1m\] \w \[\033[31m\]\`ruby -e \"print
 
 (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ')\"\`\[\033[37m\]$\[\033[00m\] "
$ nano .gitconfig 
[user]
	name = Fabwice
	email = Fabwice @ ... .com
[core]
	editor = nano
	quotepath = false
[status]
	showUntrackedFiles = all
[diff]
	renamelimit = 0
	tool = Kaleidoscope
[merge]
	conflictstyle = merge
[color]
	ui = auto
[help]
	autocorrect = 10
[alias]
[alias]
        undo = reset --hard HEAD~1
        uncommit = reset HEAD~1
        redo = reset --hard HEAD@{1}
        wip = "!git add -A; git ls-files --deleted -z | xargs -0 - I {} git rm {}; git commit -m \"wip\""
        unwip = "!git log -n 1 | grep -q -c wip && git reset HEAD~1"
        addall = "!git add -A; git ls-files --deleted -z | xargs -0 - I {} git rm {}; git status"
        # arrange et clean ton commit avant un push
        rb   = "!git wip;git rebase -i --autosquash origin/master;git unwip;git heads"
        # mettre a jour par rapport au repo distant avec merge par en bas 
        prm  = "!git fetch;git wip;git rebase --stat origin/master;git unwip;git heads"
        pr11 = "!git fetch;git wip;git rebase --stat origin/v1.1;git unwip;git heads11"
        pr13 = "!git fetch;git wip;git rebase --stat origin/v1.3;git unwip;git heads13"
        pr21 = "!git fetch;git wip;git rebase --stat origin/2.1;git unwip;git heads21"
        pr39 = "!git fetch;git wip;git rebase --stat origin/3.9;git unwip;git heads39"
        pr4 = "!git fetch;git wip;git rebase --stat origin/refonte;git unwip;git headsrefonte"
        st = status
        br = branch
        co = checkout
        cp = cherry-pick
        heads   = "!git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
        heads11 = "!git log origin/v1.1.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
        heads13 = "!git log origin/v1.3.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
        heads21 = "!git log origin/2.1.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
        heads39 = "!git log origin/3.9.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
        com = checkout master
        co4 = checkout refonte
[rerere]
	enabled = 1
[github]
        user = fabwice
        token = c....8
$ mkdir test-git
$ cd test-git/
$ git init
Initialized empty Git repository in /developpement/projets/test-git/.git/
$ ls .git/
HEAD         branches/    config       description  hooks/       info/        objects/     refs/
$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
$ echo "Je suis un fichier de test" > fichier.txt
$ git add fichier.txt 
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   fichier.txt
#
$ git commit -m "premier commit"
[master (root-commit) 40edd91] premier commit
 1 files changed, 1 insertions(+), 0 deletions(-)fabwice
 create mode 100644 fichier.txt
(master) $ git log
commit 40edd9142ceb4780a2296668745e1d10e0faf258
Author: fabwice <fabwice@....com>
Date:   Thu Dec 22 11:41:27 2011 +0100
 
    premier commit
(master) $ git log --oneline
40edd91 premier commit
(master) $ git reflog
40edd91 HEAD@{0}: commit (initial): premier commit
(master) $ echo "modification du fichier" >> fichier.txt
(master) $ 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:   fichier.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
(master) $ git commit -a -m "modification du fichier" 
[master b21b618] modification du fichier
 1 files changed, 1 insertions(+), 0 deletions(-)
(master) $ git status
# On branch master
nothing to commit (working directory clean)
(master) $ git log --oneline
b21b618 modification du fichier
40edd91 premier commit
(master) $
$ git branch -m old_branch new_branch         # Rename branch locally    
$ git push origin :old_branch                 # Delete the old branch    
$ git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
  • developpement/git.txt
  • Dernière modification: 2018/10/13 14:59
  • (modification externe)