This is an old revision of the document!


GIT

Reference

Configuration locale

$ mkdir Git
$ cd Git
$ git config --global user.name jehanproc
$ git config --global user.email my.mail@int-evry.fr
$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto
$ git init
Initialized empty Git repository in /mci/mci/login/Git/.git/
$ cat ~/.gitconfig 
[user]
	name = jehanproc
	email = my.mail@int-evry.fr
[color]
	diff = auto
	status = auto
	branch = auto

manipulations

statut initial

$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

ajout 1er fichier

$ vim file1.txt

$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	file1.txt
nothing added to commit but untracked files present (use "git add" to track)


$ git add file1.txt

$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   file1.txt

commit

$ git commit -m "add initial file1.txt" 
[master (root-commit) b679adb] add initial file1.txt
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file1.txt

$ git status
# On branch master
nothing to commit (working directory clean)

modification

$ vim file1.txt 

$ 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:   file1.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

diff

$ git diff 
diff --git a/file1.txt b/file1.txt
index ce01362..94954ab 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1 +1,2 @@
 hello
+world

commit du diff

commit -a = commit de toutes les modifications .

$ git commit -a -m "modification de file1.txt -> +world"
[master 9058851] modification de file1.txt -> +world
 1 files changed, 1 insertions(+), 0 deletions(-)

$ git status
# On branch master
nothing to commit (working directory clean)

affichage log

$ git log
commit 9058851ef6738163117ada54a94dbfc04365061c
Author: jehanproc <my.email@int-evry.fr>
Date:   Tue Apr 9 10:01:05 2013 +0200

    modification de file1.txt -> +world

commit b679adb3b2e2fa5e30d1f52b2fa4f12cff888b66
Author: jehanproc <my.email@int-evry.fr>
Date:   Tue Apr 9 09:51:01 2013 +0200

    add initial file1.txt

annuler le dernier commit

$ git reset --hard HEAD^
HEAD is now at b679adb add initial file1.txt

$ cat file1.txt 
hello

branch

par defaut, une seule branche *master*

$ git branch
* master

creation d'un branche *option1* , ne modifie en rien les fichiers (pas de recopie)

$ git branch option1

$ git branch
* master
  option1

$ ls -al
total 52
-rw-r--r--   1 login mci     6  9 avril 10:11 file1.txt
drwxr-xr-x   8 login mci  4096  9 avril 10:11 .git

passage sur la branche option1 , git checkout est utilisé pour changer de branche mais aussi pour restaurer un fichier tel qu’il était lors du dernier commit. La commande a donc un double usage.

$ git checkout option1
Switched to branch 'option1'

$ git branch
  master
* option1

$ ls -al
total 52
-rw-r--r--   1 login mci     6  9 avril 10:11 file1.txt
drwxr-xr-x   8 login mci  4096  9 avril 10:28 .git

modif branche

$ vim file1.txt
$ cat file1.txt 
hello

wild

$ git commit -a -m "ajout l3 wild dans file1"
[option1 9c17567] ajout l3 wild dans file1
 1 files changed, 2 insertions(+), 0 deletions(-)

$ git status
# On branch option1
nothing to commit (working directory clean)

$ git log
commit 9c17567714d9158126d39d3b1dda20ebe5146d82
Author: jehanproc <jehan.procaccia@int-evry.fr>
Date:   Tue Apr 9 11:18:36 2013 +0200

    ajout l3 wild dans file1

commit b679adb3b2e2fa5e30d1f52b2fa4f12cff888b66
Author: jehanproc <jehan.procaccia@int-evry.fr>
Date:   Tue Apr 9 09:51:01 2013 +0200

    add initial file1.txt

branch master

$ git checkout master
Switched to branch 'master'
$ git log 
commit b679adb3b2e2fa5e30d1f52b2fa4f12cff888b66
Author: jehanproc <jehan.procaccia@int-evry.fr>
Date:   Tue Apr 9 09:51:01 2013 +0200

    add initial file1.txt
    
$ cat file1.txt 
hello

modification

$ vim file1.txt 
$ cat file1.txt 
hello
world
$ git commit -a -m "add l2 +world file1" 
[master 5d03c08] add l2 +world file1
 1 files changed, 1 insertions(+), 0 deletions(-)

merge

on merge option1 dans master

$ git merge option1
Auto-merging file1.txt
CONFLICT (content): Merge conflict in file1.txt
Automatic merge failed; fix conflicts and then commit the result.

constat du conflit

$ cat file1.txt 
hello
<<<<<<< HEAD
world
=======

wild
>>>>>>> option1

gestion du conflit

$ vim file1.txt
$ cat file1.txt 
hello
world
wild

commit

$ git commit -a -m "marge master et option1, resolution conflit file1"
[master 8fedaa6] marge master et option1, resolution conflit file1

$ git status
# On branch master
nothing to commit (working directory clean)

Destruction de branche .

$ git branch -d option1
Deleted branch option1 (was 9c17567).

ssh git server

cle ssh

echange de clé avant “fermeture” du shell gituser

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/gituser/.ssh/id_rsa): 
Created directory '/home/gituser/.ssh'.


[procacci@arvouin ~/.ssh]
$ ssh-copy-id gituser@svnshare.it-sudparis.eu

configuration gituser

# yum install git
# useradd -m -d /home/gituser gituser
# usermod -s /usr/bin/git-shell gituser
# tail -2 /etc/shells
/bin/csh
/usr/bin/git-shell 
# mkdir git-shell-commands
# chmod 755 git-shell-commands
# cp /usr/share/doc/git-1.7.4.1/contrib/git-shell-commands/* /home/gituser/git-shell-commands/
# chown -R gituser /home/gituser/git-shell-commands/*
# chmod +x /home/gituser/git-shell-commands/list /home/gituser/git-shell-commands/help 

git bare server repo

# su -s /bin/bash - gituser
$ mkdir gittuto.git
$ cd gittuto.git/
$ git --bare init
Initialized empty Git repository in /home/gituser/gittuto.git/

git remote client

sur le client on declare notre serveur remote qui va heberger notre repo; git remote add [nomcourt] [url]

$ git remote add tuto ssh://gituser@gitshare.tem-tsp.eu/~/gittuto.git

verification de la declaration et des repo remote disponibles

$ git remote -v 
tuto	ssh://gituser@gitshare.tem-tsp.eu/~/gittuto.git (fetch)
tuto	ssh://gituser@gitshare.tem-tsp.eu/~/gittuto.git (push)

git push

on pousse alors notre depot (branche master) local vers le serveur

$ git push tuto master
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (12/12), 917 bytes, done.
Total 12 (delta 1), reused 0 (delta 0)
To ssh://gituser@gitshare.tem-tsp.eu/~/gittuto.git
 * [new branch]      master -> master

sur le serveur le directory “objects” a evolué

[gituser@gitshare gittuto.git]$ ls -ltra
drwxrwxr-x  4 gituser gituser 4096 Apr  9 14:54 refs
drwxrwxr-x  2 gituser gituser 4096 Apr  9 14:54 info
drwxrwxr-x  2 gituser gituser 4096 Apr  9 14:54 hooks
-rw-rw-r--  1 gituser gituser   23 Apr  9 14:54 HEAD
-rw-rw-r--  1 gituser gituser   73 Apr  9 14:54 description
-rw-rw-r--  1 gituser gituser   66 Apr  9 14:54 config
drwxrwxr-x  2 gituser gituser 4096 Apr  9 14:54 branches
drwxrwxr-x  7 gituser gituser 4096 Apr  9 14:54 .
drwxrwxr-x 16 gituser gituser 4096 Apr  9 15:08 objects
docpublic/systemes/linux/git.1365513123.txt.gz · Last modified: 2013/04/09 13:12 by PROCACCIA
CC Attribution-Noncommercial-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0