Ceci est une ancienne révision du document !


Git

git clone git@framagit.org:mres-web/site_MRES_squelette.git

Pour Framagit, renseigner au préalable dans les paramètres du compte la clé publique du PC, à récuperer dans ~/.ssh/id_rsa.pub

git fetch origin

Créer une branche : 1)

git branch nomdelabranche

Basculer sur cette branche :

git checkout nomdelabranche

Faire ces deux actions (créer et basculer sur une nouvelle branche) en une seule commande avec un raccourci :

git checkout -b nomdelabranche

A la racine des sources, jouer les commandes suivantes :

git init
git add .
git commit -m 'Initial Commit'

Sources : Git Basics - Getting a Git Repository

S'il existe déjà un dépôt Git, le cloner :

git clone --bare my_project my_project.git

Exemple avec un dossier SMB (sous windows)

git clone --bare "C:\Users\ajacquemin\Sources\dsi\nom_depot" "\\\\serveurfichiers\...\git\gdm\dsi\nom_depot.git"

Exemple sous Linux

git clone --bare ~/Webmastering/backup/dokuwiki-git/ /media/eddie/public/git/dokuwiki.git

Sources : Getting Git on a Server et Git bare vs. non-bare repositories

$ git remote -v
origin  //Efiles.feel-it.mad/xanit/sources_dvpt/git/gdm/commerce/bonkdostor-gdm (fetch)
origin  //Efiles.feel-it.mad/xanit/sources_dvpt/git/gdm/commerce/bonkdostor-gdm (push)

Sources : Working with Remotes

git remote add origin "///Efiles.feel-it.mad\xanit\sources_dvpt\git\gdm\ecommerce\ExportJobGDMToSparkow.git"

Remplacer origin par le nom du dépôt

# Changer l'URL d'un dépôt distant
$ git remote set-url origin "….git"
 
# Renommer un dépôt distant
$ git remote rename origin newname

Remplacer origin par le nom du dépôt distant

Obtenir la liste de tous les fichiers modifiés par un commit donné

git diff-tree --no-commit-id --name-only -r <commit id>

Source : http://stackoverflow.com/questions/424071/how-to-list-all-the-files-in-a-commit

Liste tous les fichiers qui diffèrent entre deux branches :

git diff --stat=120 branche1..branche2

Source : http://stackoverflow.com/questions/9834689/comparing-two-branches-in-git#9834872

git filter-branch -f --env-filter \
    'if [ $GIT_COMMIT = ee75eb2698bb3c2da694eb3599ad7a990999d1f3 ]
     then
         export GIT_AUTHOR_DATE="Sun Feb 09 22:00:00 2014 +0100"
         export GIT_AUTHOR_DATE="Sun Feb 09 22:00:00 2014 +0100"
     fi'

Source : http://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git

git-author-rewrite.sh
#!/bin/sh
 
git filter-branch --env-filter '
 
OLD_EMAIL="arnaud@jacquemin.info"
CORRECT_NAME="Arnaud Jacquemin"
CORRECT_EMAIL="arnaud.jacquemin+framagit@free.fr"
 
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Supprimer définitivement le dernier commit non poussé :

git reset --hard HEAD~1

Supprimer le dernier commit non poussé tout en conservant les modifications dans la staging area :

git reset --soft HEAD~1

Revenir dans l’étant du commit précédent en appliquant un nouveau commit qui est exactement l’opposé du précédent : très pratique pour annuler un commit qui a déjà été poussé, et qu’on ne peut donc pas supprimer du dépôt central sans gêner les collaborateurs :

git revert HEAD~1

Source : http://gebeo.info/2014/05/13/git-annuler-le-dernier-commit/

Annuler partiellement un commit déjà poussé :

git revert <sha-of-bad-commit> --no-commit
git reset   # sortir les modification de la staging area
# effectuer les éventuelles corrections souhaitées
git add <file> # ajouter les modifications souhaitées dans le staging
git checkout . # pour ne pas modifier les autres fichiers (d'où l'annulation partielle)
git commit

Source : http://stackoverflow.com/questions/5669358/can-i-do-a-partial-revert-in-git#5669428

LOGINOVH=login
ssh ${LOGINOVH}@ssh.cluster006.ovh.net
#Sur le serveur OVH
NOMPROJET=nom_projet
mkdir -p ~/sources/${NOMPROJET}.git
cd ~/sources/${NOMPROJET}.git
git init --bare
#En local
NOMPROJET=nom_projet
LOGINOVH=login
cd ./${NOMPROJET}
git remote add ovh ssh://${LOGINOVH}@ssh.cluster006.ovh.net/home/${LOGINOVH}/sources/${NOMPROJET}.git
git push ovh master

Source : http://wiki.rezo-zero.com/index.php?title=Cr%C3%A9er_un_d%C3%A9p%C3%B4t_nu_sur_OVH&oldid=657

A lire aussi : https://blog.jtlebi.fr/2013/11/30/gerer-son-site-avec-git-sur-un-serveur-mutualise/

git repack -a && rm ./objects/info/alternates

Cf. http://randyfay.com/content/git-clone-reference-considered-harmful

git push --delete origin tagname
git tag -d tagname

Source : http://stackoverflow.com/questions/5480258/how-to-delete-a-remote-tag

Remove untracked files from the current directory as well as any files that Git usually ignores.

# Undo changes in tracked files
git reset --hard
# Remove untracked files
git clean -df

Source : https://www.atlassian.com/git/tutorials/undoing-changes/git-clean


  • memo/git.1733570809.txt.gz
  • Dernière modification : il y a 15 mois
  • de Arnaud Jacquemin