git : fiche pratique

Cet article est une fiche pratique (commandes de base) pour Git.
  • Client Windows : perso j'utilise Msysgit. Il y en a plein évidemment...
  • Git derrière un proxy ? 2 solutions :
 export http_proxy=http://user:pass@host:port
 git config --global http.proxy http://user:pass@host:port
  • Un problème de certificats SSL ?
 git config --global http.sslVerify false
  • Visualiser l'historique d'un dépôt (avec msysgit)
 gitk --all &
  • récupérer un dépôt distant
 git clone https://domain.com/repo.git
  • connaître l'état du dépot
 git status
  • indexer l'ensemble des modifications : supprimer les fichiers, ajouter les fichiers manquants ou modifiés
 git add --all .
  • annuler des modifications locales non commitées
 git reset --hard
  • résoudre un conflit (lors d'un merge ou cherry-pick..)
 git mergetool
  • creer un tag
 git tag -a monTag -m 'monTag Il est beau'
 git push --tags 
  • déplacer un tag sur la version actuelle
 git tag -f -a monTag 
 git push origin :refs/tags/monTag 
 git push --tags 
  • positionner des alias de commandes git : dans le fichier de config global (~/.gitconfig)
 [alias]
        #Basic
        co = checkout
        st = status -s
        ci = commit
        br = branch
        df = diff
        cp = cherry-pick
        cl = clone
        diff = diff --word-diff
        dc = diff --cached
        who = shortlog -s --
        r  = !git ls-files -z --deleted | xargs -0 git rm
        #revert last commit
        rollback = reset --soft HEAD~1
        #Commit using previous message
        reapply = commit -c ORIG_HEAD
        #Logs
        lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %an - %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
        #Les logs du user
        mylg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %an - %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative --author="Vincent\\ Bostoen"
        ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
        lol = log --graph --decorate --pretty=oneline --abbrev-commit
        lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
        #Lister les commits pas encore pushés
        ctp = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %an - %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative origin/master..master
        #Mettre un fichier en argument pour avoir ses modifications
        fl = log -u
        #Avoir le contenu du dernier commit
        dl = "!git ll -1"
        #Avoir le diff avec un commit
        diffr = "!f() { git diff "$1"^.."$1"; }; f"
        #Lister tous les chemins pour un nom de fichier
        f = "!git ls-files | grep -i"
        #Chercher tous les fichiers contenant une chaine de caractère
        gr = grep -Ii
        #Lister les alias
        la = "!git config -l | grep alias | cut -c 7-"
        #Remove all locally deleted file (git rm on all 'D' files)
        rma = "!git diff -z --name-only --diff-filter=D | xargs -0 git rm"
        #Stash
        sl = stash list
        sa = stash apply
        ss = stash save
        amend = !git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend
        ignore=!([ ! -e .gitignore ] && touch .gitignore) | echo $1 >>.gitignore
        up = !sh -c 'git pull --rebase --prune && git log --pretty=format:\"%Cred%ae %Creset- %C(yellow)%s %Creset(%ar)\" HEAD@{1}..'
        bt = for-each-ref --format='%(refname:short) <- heads="" pre="" refs="" upstream:short="">

Aucun commentaire:

Enregistrer un commentaire