URL: https://linuxfr.org/users/ghusson/journaux/git-les-bases-et-guide-d-utilisation-en-mode-centralise-a-la-svn Title: Git : les bases et guide d'utilisation en mode centralisé (à la SVN) Authors: ghusson Date: 2016年11月24日T10:17:12+01:00 License: CC By-SA Tags: svn, repository, centralisé, liberasys et git Score: -2 Après une demi journée passée à lire de la documentation sur git, je partage la synthèse. Mon besoin est de créer un repository central et de travailler à la manière de SVN. Remarque : GIT est à la base conçu pour travailler de manière décentralisée. Pour ma société Liberasys, je voulais quelque chose de simple, efficace. Le mode de fonctionnement SVN correspond à ce que je veux. Les notes sont en anglais, désolé pour les non anglophones. ```bash # from : https://git-scm.com/docs/gitcore-tutorial # Directories .git/objects/ : real repository data (identified by SHA-1) .git/refs/ : references to objects (heads of development, revision tags) # Remarquable files .git/HEAD : Master head : points to default branch .git/index : describes your current working tree # Objects types and content # RQ : objects are immutable git cat-file -t 557db03de997c86a4a028e1ebd3a1ceb225be238 : gives the type of the file git cat-file blob 557db03de997c86a4a028e1ebd3a1ceb225be238 : gives the content of the file # Diff commands and comparisons (by Jon Loeliger) : diff-tree +----+ | | | | V V +-----------+ | Object DB | | Backing | | Store | +-----------+ ^ ^ | | | | diff-index --cached | | diff-index | V | +-----------+ | | Index | | | "cache" | | +-----------+ | ^ | | | | diff-files | | V V +-----------+ | Working | | Directory | +-----------+ # Configure information about git user git config --global user.email "user@domain" git config --global user.name "firstname lastname" # Initialise git repository mkdir test && cd test git init # Populating repository echo "Hello World">hello # Index (cache) echo "Silly example">example git update-index --add hello example # Get diff-files : difference between current working directory and index file git diff-files : raw summary git diff : readable differences (= git diff-files -p) # Get diff-index git diff HEAD (= git diff-index -p HEAD) : differences between a commited tree and the working directory git diff-index --cached -p HEAD : compares a tree and the index cache content # Create a tree git write-tree : Raw way to create a tree # Create initial master tree (new commited tree, related to nothing else : the master tree) tree=$(git write-tree) commit=$(echo 'Initial commit' | git commit-tree $tree) git update-ref HEAD $commit # Making a change # Process : working tree -> index file -> commited tree git rm : remove files from index (=git update-index --remove ) git add ) git update-index hello example : updates index of files git diff : show differences with index git diff HEAD : show the differences with a tree (HEAD pointer tree) git commit : store a change in the repository, give a commit message ! : all lines beginning with # will be ignored # Get diff-tree : difference between two trees git diff-tree -p HEAD : difference between the commited tree and the master tree git diff-tree -p HEAD --pretty : idem, with metadata of commits # Tags git tag my-first-tag : light tag (branch put in the .git/refs/tags/ diretory rather than .git/logs/refs/heads) git diff my-first-tag : diff between the tag and the working directory git tag -s my-major-tag : real git object, will sign current HEAD git tag : tag from a branch # Branches git checkout -b : creates a branch (pointer into the Git object database in .git/refs/heads/) git checkout -b : creates a branch from an earlyer commit (tag or branch) git branch : displays the current branch # Copy locally a repository cp -a repo-src repo-dst cd repo-dst git reset # does : git read-tree --reset HEAD # total index rebuild git update-index --refresh # makes sure to match up all index entries with the checked-out files # Copy remotely a repository git clone git://git.kernel.org/pub/scm/git/git.git/ my-git cd my-git git checkout # Switch between tags and branches git checkout : name can be a branch or a tag # === Git, SVN way (with user groups) / server # install git-core and git packages adduser git mkdir /pub mkdir /pub/my-repo.git chown -R git:git /pub/my-repo.git su - git cd /pub/my-repo.git git --bare init --shared # gives SSH accces to this directory from the users # remark : you can use git-shell in order to limit system exposure # as root: USERNAME="myuser" KEYSDIR="/data/keys" adduser --shell /usr/bin/git-shell --ingroup git --disabled-password ${USERNAME} mkdir -p ${KEYSDIR}/${USERNAME} cd ${KEYSDIR}/${USERNAME} ssh-keygen -t rsa -b 4096 -f ${USERNAME}_rsa_4096 -P "" mkdir /home/${USERNAME}/.ssh cp ${USERNAME}_rsa_4096.pub /home/${USERNAME}/.ssh/authorized_keys chmod 700 /home/${USERNAME}/.ssh chmod 600 /home/${USERNAME}/.ssh/authorized_keys chown -R ${USERNAME}:git /home/${USERNAME}/.ssh # now send the ${USERNAME}_rsa_4096 file to your new user # ask him to put a passphrase to the key with : ssh-keygen -f -p # ask him to put the file in ~/.ssh/git_ # === Git, SVN way (with user groups) / user # if not already done for the user : git config --global user.email "user@domain" git config --global user.name "firstname lastname" # 1) === initial clone export GIT_SSH_COMMAND='ssh -i ' git clone foo.com:/pub/my-repo.git cd my-repo # remark : either do the export each time you use a new shell, either configure the .ssh/config file # 2) TO DO ONLY ONE TIME : create master tree and HEAD link tree=$(git write-tree) commit=$(echo 'Initial commit' | git commit-tree $tree) git update-ref HEAD $commit git push origin master # 3) === make local changes then commit them locally # do not forget git add/rm/mv git diff git diff -p HEAD git commit # or : git commit -a # 4) === fetch changes from remote repository (merge them with local repository - always commit before) git pull origin # 5) === push the commits to the remote repository git push origin master # then iterate to 3) ``` Je ne sais pas si le mode de fonctionnement proposé est "carré". Je compte sur les commentaires acerbes des lecteurs :-) En tout cas cela fonctionne avec mes tests initiaux. J'espère que cela motivera certains à essayer voir à utiliser git au quotidien ? Par ailleurs, quand je voudrai libérer des sources, je me demande si un téléversement d'un repository sera possible et aisé vers github ou gitlab (avec reprise des versions et métadonnées) ? PS : la clef SSH initiale générée pour un utilisateur est non chiffrée. il faut donc la transmettre de manière sécurisée.

AltStyle によって変換されたページ (->オリジナル) /