155 lines
3.4 KiB
ReStructuredText
155 lines
3.4 KiB
ReStructuredText
..
|
|
Copyright (C) 2023 Jeremie Salvi.
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3
|
|
or any later version published by the Free Software Foundation;
|
|
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
|
A copy of the license is included in the section entitled "GNU
|
|
Free Documentation License".
|
|
|
|
Git Sheatsheet
|
|
==============
|
|
|
|
Initialisation d'un dépot
|
|
-------------------------
|
|
|
|
``git init (-b master branch name) (--bare pour un dépot distant sans work area)``
|
|
|
|
Clonage, synchronisation et update
|
|
----------------------------------
|
|
|
|
Clonage
|
|
|
|
``git clone <url>``
|
|
|
|
Ou, métode que je préfère pour plus de clareté avec ``git log``, on merge dans un git init neuf
|
|
|
|
``mkdir /path/to/project``
|
|
``cd /path/to/project``
|
|
``git init``
|
|
``git remote add origin ssh://user@git-server/path/to/myrepo.git``
|
|
``git pull``
|
|
``git merge origin/master``
|
|
|
|
Pousser un dépot local sur un dépot distant qui vient d'être initalisé
|
|
|
|
``git remote add origin ssh://user@git-server/path/to/myrepo.git``
|
|
``git push --set-upstream origin master``
|
|
|
|
Synchronisation
|
|
|
|
``git fetch``
|
|
|
|
``git pull <remote(origin)> <branch(master)>``
|
|
|
|
Update
|
|
|
|
``git push <remote(origin)> <branch(master)>``
|
|
|
|
Versionning
|
|
-----------
|
|
|
|
Pour versionner, il faut utiliser git tag.
|
|
|
|
``git tag (-a vx.x.x-rcx) (-m "comment")``
|
|
|
|
Pour synchroniser le tag avec le dépot distant,
|
|
il faut un push spécifique pour la version :
|
|
|
|
``git push branch(origin) tag(vx.x.x-rcx)``
|
|
|
|
pour supprimer un tag
|
|
|
|
``git tag -d vx.x.x``
|
|
|
|
Et pour le supprimer sur le dépot distant
|
|
|
|
``git push --delete origin v1.1.0``
|
|
|
|
Commit
|
|
------
|
|
|
|
``git commit (-a all modified files) (-m message)``
|
|
|
|
Navigation
|
|
----------
|
|
|
|
``git ls-tree``
|
|
|
|
Merge des commit
|
|
----------------
|
|
|
|
Git créer un snapshot à chaque commit, cela améliore les
|
|
performances par rapport à d'autres systèmes de versionning,
|
|
mais cela prend vite aussi beaucoup de place.
|
|
Pour alléger cela, on peut merger une suite de commit en
|
|
un seul avant de push sur le serveur. On utilise la commande suivante :
|
|
|
|
``git rebase -i(--interactive) <merge-after-this-commit>``
|
|
|
|
et on remplace les derniers "pick" dans le shell interactif par squash.
|
|
|
|
.. code-block:: bash
|
|
:linenos:
|
|
|
|
pick 309769c updating .Xressources configuration
|
|
squash 39a45ab updating .Xressources configuration
|
|
squash 76f1543 updating .Xressources configuration
|
|
|
|
|
|
example :
|
|
|
|
``git rebase -i HEAD~5``
|
|
|
|
``git rebase -i 6919b24b1285f00b59eae416faf7ccfba0987843``
|
|
|
|
``git rebase -i origin/master`` (pour push un seul commit depuis la dernièrebase
|
|
synchronisation avec la branche master de notre dépot distant)
|
|
|
|
|
|
Configuration générale
|
|
----------------------
|
|
|
|
``git config --global init.defaultBranch master``
|
|
|
|
``git config --global user.email "you@example.com"``
|
|
|
|
``git config --global user.name "Your Name"``
|
|
|
|
Workflow
|
|
--------
|
|
|
|
``git pull``
|
|
|
|
aussi souvent que nmécessaire
|
|
|
|
- ``git add``
|
|
- ``git commit``
|
|
|
|
``git rebase -i origin/master``
|
|
|
|
``git push``
|
|
|
|
Git Submodules
|
|
--------------
|
|
|
|
Ajouter un submodule
|
|
|
|
``git submodule add ssh://user@server/path/to/submodule.git submodule/path``
|
|
``cd submodule/path``
|
|
``rm -fr .* *``
|
|
``git init``
|
|
``git remote add origin ssh://beastie@ssh.debian-server/path/to/submodule.git``
|
|
``git merge origin/master``
|
|
``git commit -a``
|
|
``git push``
|
|
|
|
Modifier un submodule
|
|
|
|
``cd path/to/submodule``
|
|
``git commit -a``
|
|
``git push``
|
|
``cd path/to/project``
|
|
``git commit -a``
|
|
``git push``
|