=====videos===== git for dummies: https://www.youtube.com/watch?v=mJ-qvsxPHpY =====Mes dépots git===== liste de videos et recheches: git clone ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/videos.git Projet Staubli RubiksCube git clone ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/rubiksstaubli.git =====Autres===== IDE à essayer: https://www.gitkraken.com/features Cheatsheet de git: https://education.github.com/git-cheat-sheet-education.pdf =====Tests===== doc sur: https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-ssh sur serveur: cd ~ mkdir depotsgit cd depotsgit git init --bare test1.git Dépôt Git vide initialisé dans /home/bvdp/depotsgit/test1.git/ Si problème parce que le dépot est vide, faire: cd test1.git touch vide.txt git add vide.txt git commit git push origin master You need to run the clone command on what you are calling the server. But I bet you are not running an ssh server on your local client so that won't work anyway. Suggest you follow this approach (check the manual 'cause I'm doing this from memory) Log into the server machine. Create a bare repo using git init --bare On the client machine you can push your repo to the server. git remote add origin ssh://user@server:/GitRepos/myproject.git git push origin master sur serveur: cd ~ mkdir depotsgit && cd depotsgit mkdir monprojet.git cd monprojet.git git init --bare Dépôt Git vide initialisé dans /home/bvdp/depotsgit/monprojet.git/ sur bvandepo@bvandepo-HP-ZBook-14-G2: cd ~/testgit cd depot1 crée un alias pour remote pour qu'il pointe vers le serveur distant git remote add origin ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/monprojet.git git push origin master Énumération des objets: 9, fait. Décompte des objets: 100% (9/9), fait. Compression par delta en utilisant jusqu'à 4 fils d'exécution Compression des objets: 100% (3/3), fait. Écriture des objets: 100% (9/9), 731 octets | 731.00 Kio/s, fait. Total 9 (delta 0), réutilisés 0 (delta 0), réutilisés du pack 0 To ssh://inetdoc.net:2253/home/bvdp/depotsgit/monprojet.git * [new branch] master -> master [3]+ Fini gitk si je veux virer du fichier .git/config [remote "origin"] url = ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/monprojet.git fetch = +refs/heads/*:refs/remotes/origin/* faire: git remote remove origin sur serveur: cd ~/depotsgit cd depot3 git clone ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/monprojet.git nano ... git commit -am"change1" git push origin master équivalent grâce à l'alias à: git push ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/monprojet.git master cd depot1 git pull origin master astuce: Vous avez des branches divergentes et vous devez spécifier comment astuce: les réconcilier. Vous pouvez le faire en lançant une des astuce: commandes suivantes avant votre prochain tirage : astuce: astuce: git config pull.rebase false # fusion (stratégie par défaut) astuce: git config pull.rebase true # rebasage astuce: git config pull.ff only # avance rapide seulement astuce: astuce: Vous pouvez remplacer "git config" par "git config --global" pour que astuce: ce soit l'option par défaut pour tous les dépôts. Vous pouvez aussi astuce: passer --rebase, --no-rebase ou --ff-only sur la ligne de commande pour astuce: remplacer à l'invocation la valeur par défaut configurée. fatal: Besoin de spécifier comment réconcilier des branches divergentes. je règle l'option par défaut pour ce dépot git config pull.rebase false puis git pull origin master pour annuler les modifications sur fichier depuis le dernier commit: git restore fichier ------------------------------------------------------------------------------------------------------------------------------------------ ssh://user@server:/GitRepos/myproject.git followed by git push origin master sur rapid: git clone bvdp@inetdoc.net:/home/bvdp/depotsgit/test1.git git clone "./depot1" "ssh://bvdp@inetdoc.net:/home/bvdp/depotsgit/depot1" pour spécifier le port https://stackoverflow.com/questions/5767850/git-on-custom-ssh-port git clone ./depot1 ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/depot1 man git-clone git clone ./depot1 bvdp@inetdoc.net:depotsgit/depot1 =====ssh sans pass sous Windows 10===== https://codefaq.org/server/how-to-ssh-login-without-password-on-windows-10/ avec cmd: mkdir C:\Users\%username%\.ssh ssh-keygen notepad C:\Users\%username%\.ssh/id_rsa.pub et copier/coller le contenu via ssh dans le fichier du serveur nano .ssh/authorized_keys =====Alias pour windows===== https://www.nextinpact.com/article/29384/106591-comment-creer-alias-pour-bash-cmd-ou-powershell https://www.developpez.net/forums/d876376/systemes/windows/windows-xp/creation-d-alias-cmd/ Vous pouvez aussi utiliser jusqu'à neuf arguments ( dollar 1 à 9) et différentes commandes de suite ( dollar T comme séparateur). L'autre problème, c'est que ces macros sont non persistantes. C'est-à-dire qu'elles sont effacées dès que la fenêtre est fermée. Vous pouvez néanmoins en charger plusieurs d'un coup via un fichier : doskey ls=dir $* pour utiliser un fichier texte comme définition des macros: doskey /macrofile=fichier.txt mes macros: doskey git=C:\Users\%username%\Downloads\PortableGit\bin\git $* doskey gitk=C:\Users\%username%\Downloads\PortableGit\cmd\gitk pour rendre permanent: https://www.developpez.net/forums/d830281/general-developpement/programmation-systeme/windows/scripts-batch/alias-doskey-ne-veut-fonctionner/ Editeur de registre HKEY_CURRENT_USER->Software->Microsoft->Command Processor sous Windows 10: Ordinateur\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor Executer cmd en tant qu'administrateur puis: (git=C:\Users\%username%\Downloads\PortableGit\bin\git $* gitk=C:\Users\%username%\Downloads\PortableGit\cmd\gitk ) >> "%SystemRoot%\alias.txt" je le fais via notepad en admin: notepad "%SystemRoot%\alias.txt" et ajouter: git=C:\Users\%username%\Downloads\PortableGit\bin\git $* gitk=C:\Users\%username%\Downloads\PortableGit\cmd\gitk pour ajouter la clef: reg add "HKCU\Software\Microsoft\command processor" /v AutoRun /d "Doskey /MACROFILE=%SystemRoot%\alias.txt" /f >nul sous Windows 10: reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor" /v AutoRun /d "Doskey /MACROFILE=%SystemRoot%\alias.txt" /f >nul ----------------------------------------- git config --global user.name "Bertrand Vandeportaele" git config --global user.email bertrand.vandeportaele@iut-tlse3.fr C:\Users\B\Desktop\staubli2022\Demo_rubiks_bvdp\CELL_IUT0> git init git add * pb encodage ascii sous windows: warning: LF will be replaced by CRLF in CAD/adaptateur_pince_bouchon_iut2021_open.stl. The file will have its original line endings in your working directory git commit -m"ajout de tous les fichiers en version initiale" sur inetdoc.net: cd ~/depotsgit git init --bare rubiksstaubli.git sur i7: cd C:\Users\B\Desktop\staubli2022\Demo_rubiks_bvdp\CELL_IUT0 git remote add origin ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/rubiksstaubli.git git push origin master récupérer depuis rapid (crée un sous dossier rubiksstaubli): cd ~/testgit git clone ssh://bvdp@inetdoc.net:2253/home/bvdp/depotsgit/rubiksstaubli.git =====Annuler propremment un commit pushé===== https://makina-corpus.com/devops/git-annuler-proprement-un-commit-apres-un-push git revert HEAD~1..HEAD =====Cheat===== En complément de man, fournit des exemples pour des commandes utiles sudo snap install cheat cheat git # To set your identity: git config --global user.name git config --global user.email # To set your editor: git config --global core.editor # To enable color: git config --global color.ui true # To stage all changes for commit: git add --all # To stash changes locally, this will keep the changes in a separate changelist # called stash and the working directory is cleaned. You can apply changes # from the stash anytime git stash # To stash changes with a message: git stash push -m # To list all the stashed changes: git stash list # To apply the most recent change and remove the stash from the stash list: git stash pop # To apply any stash from the list of stashes. This does not remove the stash # from the stash list git stash apply stash@{6} # To commit staged changes: git commit -m # To edit previous commit message: git commit --amend # Git commit in the past git commit --date="`date --date='2 day ago'`" git commit --date="Jun 13 18:30:25 IST 2015" # more recent versions of Git also support --date="2 days ago" directly # To change the date of an existing commit: git filter-branch --env-filter \ 'if [ $GIT_COMMIT = 119f9ecf58069b265ab22f1f97d2b648faf932e0 ] then export GIT_AUTHOR_DATE="Fri Jan 2 21:38:53 2009 -0800" export GIT_COMMITTER_DATE="Sat May 19 01:01:01 2007 -0700" fi' # To remove staged and working directory changes: git reset --hard # To go 2 commits back: git reset --hard HEAD~2 # Checkout the fb branch, and rebase from git reset --hard / # To revert first/initial commit on a branch: # Running git reset --hard HEAD~1 will give error: # fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree. git update-ref -d HEAD # To remove untracked files: git clean -f -d # To remove untracked and ignored files: git clean -f -d -x # To push to the tracked master branch: git push origin master # To push to a specified repository: git push git@github.com:/.git # Tags: Tag a commit git tag -a -m "" # Tags: To push a tag to remote: git push origin # Tags: To delete a tag on remote git push --delete origin # Tags: To delete a tag locally git tag -d # To force a push: git push -f # Branches: To delete the branch : git branch -D # Branches: To delete a local : git branch -d # Branches: To delete a remote branch : git push --delete origin # Branches: To delete all branches on remote that are already merged: git branch --merged | egrep -v "(^*|main|dev)" | xargs git branch -d # Branches: To make an exisiting branch track a remote branch: git branch -u upstream/foo # To see who commited which line in a file: git blame # To sync a fork with the master repo: git remote add upstream git@github.com:/.git # Set a new repo git remote -v # Confirm new remote repo git fetch upstream # Get branches git branch -va # List local - remote branches git checkout master # Checkout local master branch git checkout -b new_branch # Create and checkout a new branch git merge upstream/master # Merge remote into local repo git show 83fb499 # Show what a commit did. git show 83fb499:path/fo/file.ext # Shows the file as it appeared at 83fb499. git diff branch_1 branch_2 # Check difference between branches git log # Show all the commits git status # Show the changes from last commit # To view the commit history of a set of files: git log --pretty=email --patch-with-stat --reverse --full-index -- Admin\*.py > Sripts.patch # To import commits from another repo: git --git-dir=../some_other_repo/.git format-patch -k -1 --stdout | git am -3 -k # To view commits that will be pushed: git log @{u}.. # To view changes that are new on a feature branch: git log -p feature --not master git diff master...feature # To perform an interactive rebase for the prior 7 commits: git rebase -i @~7 # To diff files WITHOUT considering them a part of git: # This can be used to diff files that are not in a git repo! git diff --no-index path/to/file/A path/to/file/B # To pull changes while overwriting any local commits: git fetch --all git reset --hard origin/master # To pull down a remote branch, but rebase any locally differing commits onto # the top of the incoming commits: git pull --rebase # To update all submodules: git submodule update --init --recursive # To perform a shallow clone to only get latest commits: # (helps save data when cloning large repos) git clone --depth 1 # To unshallow a clone: git pull --unshallow # To create a bare branch (one that has no commits on it): git checkout --orphan branch_name # To checkout a new branch from a different starting point: git checkout -b master upstream/master # To remove all stale branches (ones that have been deleted on remote): So if # you have a lot of useless branches, delete them on Github and then run this: git remote prune origin # To prune all remotes at once: git remote prune $(git remote | tr '\n' ' ') # Revisions can also be identified with :/text # So, this will show the first commit that has "cool" in their message body git show :/cool # To undo parts of last commit in a specific file: git checkout -p HEAD^ -- /path/to/file # To revert a commit and keep the history of the reverted change as a separate revert commit: git revert # To pick a commit from a branch to current branch. This is different than # merge as this just applies a single commit from a branch to current branch: git cherry-pick # Change author of a commit: git commit --amend --author="Author Name " # The GPG key used for signing your commits git config --global user.signingkey 0A46826A # Sign new tags: git tag -s v1.5 -m 'my signed 1.5 tag' # Sign a commit: git commit -a -S -m 'Signed commit' # check any signatures it finds and list them in its output: git log --pretty="format:%h %G? %aN %s" # Defined the key to use for signing commits: git config user.signingkey [KEYID] # Set signing of commits globally: git config --global commit.gpgsign true # To list unstracked files: git ls-files --others --exclude-standard =====hébergement de copie de dépots===== https://fr.flossmanuals.net/guide-git/creation-et-duplication-dun-depot-repository/ git clone depot_source [depot_destination] Ce qui va donner... - En local: git clone /chemin/vers/depot nouveau_depot - Distant via un protocole donné: git clone :/:/chemin/vers/depot - via git: git clone git://utilisateur@hote:/chemin/vers/depot - via ssh: git clone ssh://utilisateur@hote:/chemin/vers/depot - via https: git clone https://hote:/chemin/vers/depot - =====général git===== création du git dans le dossier courant git init pour ajouter un fichier avec git (il faut le faire pour tous les fichiers nouveaux ou que l'on a modifié): git add test/test.cpp pour commiter en local A FAIRE DANS MTI/work..../ git commit ensuite saisir le commentaire associé puis faire :x pour sauver pour voir les dernier commit A FAIRE DANS MTI/work..../ git log pour selectionner les parties de diff que l'on veut ajouter à un commit, pour ne pas polluer un commit avec des modifications qui n'ont rien à voir git add -p files avant de commiter pour voir les modifs locales non encore commitées A FAIRE DANS MTI/work..../ : git status a faire une fois au début pour s'identifier git config --global user.name "Vandeportaele Bertrand" git config --global user.email bvandepo@laas.fr git config --global --add core.editor vim cat ~/.gitconfig pour afficher les différences des fichiers A FAIRE DANS MTI/work..../ git diff pour récuperer la derniere version commitée en local d'un fichier (annule les dernières modifications) git checkout src/MTI.cpp pour tout commiter A FAIRE DANS MTI/work..../ , attention ne pas faire si on a des fichiers qu'on ne veut pas commiter (par exemple makefile.in de MTI) git commit -a pour inclure un message au commit git commit -a -m "message" pour montrer des stats sur les fichiers modifiés à chaque commit git log --stat pour supprimer un fichier du git "Convert WebPages to MPFS.sh" sans tenir des modifs locales git rm -f "Convert WebPages to MPFS.sh" pour recharger les derniers push effectués par les autres depuis notre dernier pull et checker les compatibilités avant de pusher, l'option rebase permet de positionner notre prochain push (mes commits) en haut de la liste git pull --rebase si il y a des incompatibilité de merge, des balises sont placées dans les fichiers, effacer les balises et corriger les problèmes puis faire: git rebase --continue pour ecraser un fichier en local par la version du dépot: git checkout -- conf/airframes/LAAS/mmlaas_N1.xml pour soumettre mes modifs au dépot git git push Pour générer la liste des fichiers qui ont changé: git status | grep modified | sed ':a;{N;s/\n/ /};ba' | sed 's/[[:space:]]*#[[:blank:]]*modified:[[:blank:]]*/ /g' Cheat-sheet sur les regexp: http://krijnhoetmer.nl/stuff/regex/cheat-sheet/ Pour le remplacement du \n avec sed: http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed To resynchronize with the head branch, keeping the local change (since the last commit): cd dossiergérépargit git pull git stash git pull git stash pop Pour effacer le dernier commit, en conservant en local les modifications sur les fichiers: git reset --soft HEAD~1 Pour effacer le dernier commit, en effacant en local les modifications sur les fichiers: git reset --hard HEAD~1 Pour mettre de coté les modifications locales le temps de faire des push/pull etc (détails https://git-scm.com/docs/git-stash ): git stash pour restaurer ces modifications : git stash pop pour voir les modifications entre deux commits différents sur un fichier; git diff 24c3b0f3e85f494ec30334025c608eafbb91738b 70364982a52fd9e8c47fbd00ddbea34f208750d2 pour voir les modifications entre deux commits différents sur un fichier; git diff 24c3b0f3e85f494ec30334025c608eafbb91738b 70364982a52fd9e8c47fbd00ddbea34f208750d2 ./ORBextractor.cc pour revenir à une version commité antérieurement, d'abord s'assurer que tout les fichiers en cours de modifications sont commités puis: git checkout 872b6f963cc3fa7b8130b4dd6e8d76662282f714 ===Sur GitHub=== https://help.github.com/articles/fork-a-repo/ https://help.github.com/articles/creating-a-pull-request/ https://confluence.atlassian.com/bitbucket/branching-a-repository-223217999.html fork sur github: https://github.com/bvandepo/ORB_SLAM2 http://stackoverflow.com/questions/11619593/how-to-change-the-fork-that-a-repository-is-linked-to je veux garder le repo original pour beneficier des updates git remote rename origin upstream git branch -avv # existing branches like master are linked to upstream/xxx git remote add origin https://github.com/bvandepo/ORB_SLAM2 git checkout -b binaryVocabularyFileBranch git add... git commit -m"..." git push Whenever you need to update your fork based on the recent evolution of the original repo: git checkout master git pull # it pulls from upstream! git checkout newFeatureBranch git rebase master # safe if you are alone working on that branch git push --force # ditto. It pushes to origin, which is your fork. Pour inviter un collaborateur sur un repo github: https://help.github.com/articles/inviting-collaborators-to-a-personal-repository/ ===Au LAAS=== https://wiki.laas.fr/robots/GitServer =====Automatisation envoi d'email par git===== http://www.systutorials.com/1473/setting-up-git-commit-email-notification/ ssh ...@trac.... cd /git/robots/embedded-vision.git/hooks cp post-receive.sample post-receive pour trouver ou est le script post-receive-email locate post-receive-email /git/jrl/corba/hpp-corba-tutorial.git/hooks/contrib/post-receive-email /git/jrl/corba/hpp-template-corba.git/hooks/contrib/post-receive-email /git/jrl/git-hooks/contrib/post-receive-email /usr/local/src/cgit/git/contrib/hooks/post-receive-email /usr/local/src/git/contrib/hooks/post-receive-email je prends le dernier et ajoute l'appel la derniere ligne de post-receive nano post-receive /usr/local/src/git/contrib/hooks/post-receive-email cd /git/robots/embedded-vision.git/ nano config ajouter [hooks] mailinglist = "cslam-developers@laas.fr" senderemail = "bvandepo@laas.fr" =====spécifique robotpkf===== regler $ROBOTPKG_BASE dans ~/.profile source .profile cd robotpkg mise à jour globale des paquets git pull cd hardware/MTI/ apres avoir commité (en local) git log gitk cd work.garossos.laas.fr/MTI-0.4/ changer dans test/Makefile.in virer le -lrt pour construire le .configure ./autogen.sh puis lancer configure en indiquant le dossier cible pour les executables (pas sur /usr.... ou il faudrait etre root) ./configure --prefix=/Users/bvandepo/openrobots which glibtoolize sudo ln -ls /usr/bin/glibtoolize /usr/bin/libtoolize dans le cas ou on travaille sur les paquets standard (sans branches), pour mettre à jour un paquet (et installer l'executable) make update confirm verbose=1 pour récuperer la dernière version du code (pas encore paquagée et stable) (ici la branche GPS de mti) make checkout confirm modifier le code si on veut puis pour recompiler: make replace confirm pour nettoyer le work make clean confirm pour enlever les executables installés du module make deinstall ===== outils graphique ===== dans le dossier courant gitk ATTENTION GITK NE MONTRE QUE LA BRANCHE COURANTE, qui a été selectionnée avec git checkout nombranche pour faire du merge avec interface graphique git mergetool =====maj===== on ne peut pas faire de checkout pour changer de branche tant que l'on a pas fait un commit des modifs liste les branches, affiche une étoile devant la brance actuellement selectionnée git branch pour merger la branche avec la branche courante git merge nombranch on peut réorganiser localement les commits avant de les pusher (par exemple les réordonner, les merger etc). rebase au lieu de merge: faire repartir une branche depuis un nouveau point d'une branche d'origine. A faire lorsque l'on veut commiter des modifs vers une branche A qui a continué d'évoluer. On dis que nos modifs doivent s'appliquer à la dernière version de la branche A. Cela crée des nouveaux commits server git au laas: trac.laas.fr quand on clone un repository ca cree un origin/master qui est l'exacte copie de master si on a taggé des commits, pour qu'ils soient pris en compte, il faut utiliser git push --tags === modules=== permet de structurer les repositories: ===gestion des range=== git dif master@{yesterday}..master master^2 parent numero 2 de master master~n ancetre numero n sur la même branche =====autres docs===== http://doc.ubuntu-fr.org/git http://git-scm.com/book/fr/Les-bases-de-Git-Travailler-avec-des-d%C3%A9p%C3%B4ts-distants =====Redmine au LAAS===== Notice sur le wiki sysadmin: https://wiki.laas.fr/sysadmin/RedmineGitSvn#Acc.2BAOg-s_au_d.2BAOk-pot_git https://wiki.laas.fr/sysadmin/RedmineGitSvn#Acc.2BAOg-s_au_d.2BAOk-pot_git Il faut ajouter à son compte utilisateur les clefs publiques générées sur les machines depuis lesquelles on veut se connecter en ssh à git.laas.fr Mes projets en cours: https://redmine.laas.fr/projects/bvandepo Pour créer un nouveau projet: new suproject (à droite) name: visapp_paper_innersense décocher wiki create and continue en haut, jump to a project-> Bertrand Vandeportaele->visapp_paper_innersense settings + New repository git create Cliquer sur le repository: ssh://git@redmine.laas.fr/laas/users/bvandepo/visapp_paper_innersense.git comme on a déjà en local fait un git init, faire comme indiqué sur Setup Existing Repository : cd existing_git_repo git remote add origin ssh://git@redmine.laas.fr/laas/users/bvandepo/visapp_paper_innersense.git git push -u origin master Pour ajouter des membres, il faut que les utilisateurs aient créé un compte sur https://redmine.laas.fr/ Settings->Members-> + New member redmine remplace l'ancien: https://wiki.laas.fr/robots/GitServer === Pour g2o=== cloné depuis github, créer un repo sur redmine et pour changer l'url: git remote set-url origin ssh://git@redmine.laas.fr/laas/users/bvandepo/g2o-direct-slam-for-lines.git git push origin master pour le récupérer: git clone ssh://git@redmine.laas.fr/laas/users/bvandepo/g2o-direct-slam-for-lines.git