Skip to content

Instantly share code, notes, and snippets.

@NerOcrO
Last active October 10, 2020 11:04
Show Gist options
  • Save NerOcrO/8324055 to your computer and use it in GitHub Desktop.
Save NerOcrO/8324055 to your computer and use it in GitHub Desktop.
git gitconfig

Ne plus taper sa passphrase à chaque commande

eval $(ssh-agent -s)
ssh-add ~/.ssh/*_rsa

Voir les logs de tous les fichiers ou d'un fichier

git log -p [FICHIER]

Voir les logs d'un auteur sur la dernière semaine

git log --oneline --since="1.week" --author="TOTO"

git log --author="TOTO" --since="1.week" --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

git shortlog --since="1.week"

Voir les fichiers sur lesquels j'ai intéragi

git log --pretty="%H" --author="[YOUR_NAME]"| while read commit_hash; do git show --oneline --name-only $commit_hash | tail -n+2; done | sort | uniq|grep ".php"

Quels sont les fichiers qui changent le plus souvent (hors renommages)

git log --format=format: --name-only | grep -v '^$' | sort | uniq -c | sort | tail -100

Rechercher qui a fait quoi

git lg -S "[WORDS]" -1 -p index.html

Permet de voir les dernières actions effectuées sur le repository

git reflog

Faire un patch

git diff -w > patches/[FILE].patch

git diff -w [FILE] > patches/[FILE].patch

git diff -w > [description]-[issue-number]-[comment-number].patch

http://blog.fclement.info/contribuer-en-tant-que-developpeur-a-drupal-via-drupal-org

Patcher un fichier qui n'existe pas encore

git add -A git ci -m 'XXX' git format-patch origin/master

Vérifier la liste des commiters

git shortlog -sne

Créer la branche distante en locale

git checkout -b [LOCAL-BRANCH] origin/[REMOTE-BRANCH]

Switch sur la branche distante

git checkout -b [BRANCH]

Revenir à un fichier précédent en cas de modification intempestive

git checkout -- [FILE]

Supprimer toutes les modifications en cours

git reset --hard

Revenir à un commit précédent

git checkout <numéro de commit grâce à git log>

Pour merger une branche

git commit -m "ce que j'ai fait"

git fetch (pour avoir toutes les modifs effectuées sur toutes les branches)

git merge -s recursive --no-commit origin/master (change de mode de merge et ne commit pas)

Si conflit, lire ce que dit git à la fin (généralement, faut refaire un commit)

git checkout prod

git pull

git log prod..master ou git diff prod master pour voir les différences

git merge master

git push

Différence entre deux fichiers

git diff branch1:file1 branch2:file2

git diff --no-index -- previous_release new_release

Puis forcer le push

git push -f origin [BRANCH]

Lancer phpcs sur mes fichiers modifiés

git status --porcelain | grep -E '^[^D\?]{2} .*\.php$' | awk '{print $2}' | xargs -n1 phpcs --standard=drupal | more

Lister les tags

git tag

Pusher les tags

git push origin --tag

Annule le dernier commit, mais laisse le répertoire de travail en l'état

git reset HEAD^

Ajouter un sous module

git submodule add <repo> <sites/all/modules/custom/my_module>

Modifier le dernier commit sans avoir push

git add [FILES]

git commit --amend

Modifier le dernier commit si on a push

La même chose qu'au dessus puis git push origin HEAD --force

Suppression des derniers commit jusqu'à un commit donné après un push

git reset --hard <sha1-commit-id>

git push origin HEAD --force

Suppression d'un commit donné après un push

git rebase -i <sha1-commit-id>~1

Suivre les instructions proposées par GIT (effacer une ligne de commit efface le commit)

git push origin HEAD --force

Changer le nom des commiters dans l'historique de git

https://help.github.com/articles/changing-author-info

Changer le message d'un commit

https://stackoverflow.com/questions/179123/edit-an-incorrect-commit-message-in-git

Errors

Si le push ne fonctionne pas, il faut vérifier l'intégrité de la clé privée

=> Rajouter les serveurs dans :

vim ~/.ssh/config

Host git.mdp.net
IdentityFile ~/.ssh/id_rsa_mine

Cool scripts

wget https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh

sudo wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash /etc/bash_completion.d/git

Copy to ~/git-prompt.sh and reload the configuration => source ~/git-prompt.sh

Documentations

#!/bin/bash
gf__status() {
gf__display_command "$RUN"
git status
}
gf__display_command() {
if [[ $RUN ]]; then
echo -e "\033[1;34m$RUN\033[0m"
eval "$RUN"
RUN=''
fi
}
gf_branch_delete_all() {
# pas reussi a l'afficher
git branch -r | awk '{print $1}' | grep -E -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
}
gf_branch_listing() {
if [[ -z $1 ]]; then
RUN="git branch"
else
RUN="git branch | grep $1 | sed 's/..\(.*\)/\1/'"
fi
gf__display_command "$RUN"
}
gf_branch_selection() {
if [[ $1 ]]; then
#branch=`\git branch | \grep $1 | \head -n 1 | \sed 's/..\(.*\)/\1/'`
branch=$(git branch | grep "$1" | head -n 1 | sed 's/..\(.*\)/\1/')
if [[ -z $branch ]]; then
RUN="git branch"
else
RUN="git checkout $branch && git branch"
fi
gf__display_command "$RUN"
fi
}
gf_branch_new() {
if [[ $1 ]]; then
RUN="git checkout -b $1 && git branch"
gf__display_command "$RUN"
fi
}
gf_add() {
if [[ $1 ]]; then RUN="git add $*"
else RUN="git add -A"; fi
gf__status "$RUN"
}
gf_addP() {
RUN="git add -p $*"
gf__status "$RUN"
}
gf_checkout() {
if [[ $1 ]]; then RUN="git checkout $*"; fi
gf__status "$RUN"
}
gf_commit() {
if [[ $1 ]]; then m=$1
else m='...'; fi
RUN="git commit -m '$m'"
gf__status "$RUN"
}
gf_status() {
gf__status
}
gf_diff() {
RUN="git diff $*"
gf__display_command "$RUN"
}
gf_log() {
RUN="git log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
gf__display_command "$RUN"
}
gf_log1week() {
RUN="git shortlog --since='1.week'"
gf__display_command "$RUN"
}
gf_pull() {
#RUN="pushd . && cd $(git rev-parse --show-toplevel) && git pull --recurse-submodules && git fetch --tags && git submodule update --init --recursive && popd"
RUN="git pull --recurse-submodules && git fetch --tags && git submodule update --init --recursive"
gf__display_command "$RUN"
gf_branch_delete_all
}
gf_push() {
RUN="git push $*"
gf__status "$RUN"
}
gf_reset() {
RUN="git reset --hard"
gf__status "$RUN"
}
gf_resetHead() {
cmd="git reset HEAD"
if [[ $1 ]]; then
for ((i=0; i < $1; ++i)); do cmd+='^'; done
fi
$cmd > /dev/null
gf__status
}
gf_clean() {
RUN="git clean -f -d"
gf__status "$RUN"
}
gf_amend() {
if [[ $1 ]]; then
set -e
cmt=$(git rev-parse "$1")
git commit --fixup="$cmt"
GIT_EDITOR=true git rebase -i --autosquash "$cmt~1"
else
RUN="git commit --amend --no-edit"
fi
gf__status "$RUN"
}
gf_clean_history() {
RUN="git gc && git prune"
gf__display_command "$RUN"
}
alias gbda=gf_branch_delete_all
alias gbl=gf_branch_listing
alias gbs=gf_branch_selection
alias gbn=gf_branch_new
alias gad=gf_add
alias gap=gf_addP
alias gco=gf_checkout
alias gci=gf_commit
alias gst=gf_status
alias gdf=gf_diff
alias gdfs='gf_diff --staged'
alias glg=gf_log
alias g1w=gf_log1week
alias gpl=gf_pull
alias gps=gf_push
alias grs=gf_reset
alias grh=gf_resetHead
alias gcl=gf_clean
alias gca=gf_amend
alias ggc=gf_clean_history
# vim ~/.gitconfig
# No need to reload the configuration
# https://gist.github.com/tdd/470582
[user]
name = NerOcrO
email = my_email@example.com
[blame]
ignoreRevsFile = .git-blame-ignore-revs
[color]
ui = auto
[color "branch"]
current = green reverse
local = red
remote = yellow
[color "diff"]
frag = magenta bold
new = green bold
meta = yellow bold
old = red bold
whitespace = white reverse
[color "status"]
added = green
branch = magenta
changed = yellow
untracked = red
updated = green
[core]
autocrlf = input
editor = vim
whitespace = -trailing-space
[diff]
mnemonicPrefix = true
renames = true
submodule = log
[fetch]
prune = true
recurseSubmodules = on-demand
[grep]
extendedRegexp = true
[http]
PostBuffer = 524288000
[log]
follow = true
[merge]
conflictStyle = diff3
[pull]
rebase = preserve
[push]
default = upstream
followTags = true
[status]
submoduleSummary = true
showUntrackedFiles = all
[tag]
sort = version:refname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment