Update git config

This commit is contained in:
xerus2000 2020-06-03 12:26:15 +02:00
parent 98ca75b8cf
commit d7fcef10bf
2 changed files with 72 additions and 55 deletions

View File

@ -1,8 +1,6 @@
[core] [core]
autocrlf = input autocrlf = input
editor = nvim editor = nvim
[diff]
tool = meld
[submodule] [submodule]
recurse = true recurse = true
[rerere] [rerere]
@ -11,6 +9,16 @@
[pack] [pack]
threads = 0 threads = 0
[diff]
tool = nvim
[merge]
tool = nvim
[mergetool "nvim"]
cmd = nvim -f -c \"Gdiffsplit!\" \"$MERGED\"
prompt = false
[difftool "nvim"]
cmd = "nvim -d \"$LOCAL\" \"$REMOTE\""
# Automatically push to branch with matching name # Automatically push to branch with matching name
[push] [push]
default = current default = current
@ -18,7 +26,7 @@
[pager] [pager]
branch = false branch = false
[grep] [grep]
lineNumber lineNumber = 1
[color "status"] [color "status"]
added = green added = green
@ -27,9 +35,15 @@
[user] [user]
email = 27jf@pm.me email = 27jf@pm.me
name = xerus name = xerus2000
[alias] [alias]
st = status -sb
stv = --paginate status -v
unstage = reset HEAD --
ready = rebase -i @{u}
curbranch = symbolic-ref --short HEAD curbranch = symbolic-ref --short HEAD
root = rev-parse --show-toplevel root = rev-parse --show-toplevel
dir = !git root | sed 's/$/\\/.git/g' dir = !git root | sed 's/$/\\/.git/g'
@ -38,4 +52,4 @@
clean = git-lfs clean -- %f clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f smudge = git-lfs smudge -- %f
process = git-lfs filter-process process = git-lfs filter-process
required required = true

View File

@ -1,51 +1,56 @@
# Tools
alias bfg='java -jar ~/daten/dropbox/tools/bfg-1.13.0.jar' alias bfg='java -jar ~/daten/dropbox/tools/bfg-1.13.0.jar'
alias gti=git alias magit='nvim -c MagitOnly'
# Repo info # Repo info
alias gr='git remote -v' alias gr='git remote -v'
alias gb='git branch -vv' alias gb='git branch -vv'
alias grev='git rev-parse --short' alias grev='git rev-parse --short'
alias ghead='git rev-parse --short HEAD' alias ghead='git rev-parse --short HEAD'
alias gref='git reflog' alias gref='git reflog'
gln() {
git --no-pager log --graph --pretty=format:"%C(auto)%h -%d %s %Cgreen(%cr) %Cblue<%an>%Creset" -5 "$@"
println
}
# Show the 5 most recent commits without pager
alias gln='git --no-pager log --pretty=tformat:"%C(auto)%h -%d %s %Cgreen(%cr) %Cblue<%an>%Creset" -5 "$@"'
# Log local and origin commits side by side - useful to check before forcing an action
glno() { glno() {
local log= loc="$(git log --pretty=format:"%C(auto)%h %s %Cgreen(%cr)" -5 "$@" --color=always "$@")"
local loc="$(git log --pretty=format:"%C(auto)%h %s %Cgreen(%cr)" -5 "$@" --color=always "$@")" origin="$(git log --pretty=format:"%C(auto)%h %s %Cgreen(%cr)" -5 "origin/$(git curbranch)" --color=always "$@")"
local origin="$(git log --pretty=format:"%C(auto)%h %s %Cgreen(%cr)" -5 "origin/$(git curbranch)" --color=always "$@")" a=$(echo $loc | wc -l)
local a=$(echo $loc | wc -l) b=$(echo $origin | wc -l)
local b=$(echo $origin | wc -l) halfcols="$(($(tput cols) / 2))"
for i in `seq 1 $([ $a -le $b ] && echo "$a" || echo "$b")`; do for i in `seq 1 $([ $a -le $b ] && echo "$a" || echo "$b")`; do
printf '%-120s %s\n' "$(echo $loc | head -n $i | tail -1)" "$(echo $origin | head -n $i | tail -1)" printf "%-${halfcols}s %s\n" "$(echo $loc | head -n $i | tail -1)" "$(echo $origin | head -n $i | tail -1)"
done done
} }
# Shortcuts # Shortcuts
alias gfs='git fetch && git status -s -b' alias gfs='git fetch && git status -s -b'
alias glu='git pull upstream $(git curbranch)'
alias gcap!='git commit -a --amend --no-edit && git push -f' alias gcap!='git commit -a --amend --no-edit && git push -f'
alias grh!='git reset --hard' alias grh!='git reset --hard'
alias grhr='git reset --hard $(git rev-parse --abbrev-ref --symbolic-full-name @{u})' alias grhr='git reset --hard $(git rev-parse --abbrev-ref --symbolic-full-name @{u})'
alias gitgc='git gc && git repack -a -d' alias gitgc='git gc && git repack -a -d'
alias gitstandup='git --no-pager log --since yesterday --author erus --all'
alias gitready='git rebase -i @{u}'
# List all branches with their last updates
alias gitwhen="git for-each-ref --sort=committerdate --format='%(refname:short) * %(authorname) * %(committerdate:relative)' refs/remotes/"
# Find a commit that follows the given one - second argument can be used to specify the search range
gitchild() { git log --reverse --ancestry-path --pretty=%H $1..${2:-HEAD} | head -1; } gitchild() { git log --reverse --ancestry-path --pretty=%H $1..${2:-HEAD} | head -1; }
gitrecache() {
# Caching
gitrecache() {
git rm --cached --quiet -r ${1:-.} git rm --cached --quiet -r ${1:-.}
git add ${1:-.} git add ${1:-.}
git status -s git status -s
} }
gitrestore() { gitrestore() {
git reset -- "$@" git reset -- "$@"
git checkout -- "$@" git checkout -- "$@"
} }
alias gitstandup='git --no-pager log --since yesterday --author Xerus --all' # Branches
alias gitready='git rebase -i @{u}' alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done'
alias gitwhen="git for-each-ref --sort=committerdate --format='%(refname:short) * %(authorname) * %(committerdate:relative)' refs/remotes/"
gitrebranch() { gitrebranch() {
branch=${1:-$(git curbranch)} branch=${1:-$(git curbranch)}
test "$(git curbranch)" = "$branch" && git checkout ${2:-master} test "$(git curbranch)" = "$branch" && git checkout ${2:-master}
@ -58,30 +63,25 @@ gitrmbranch() {
test $1 || git checkout master test $1 || git checkout master
git branch -D $branch git branch -D $branch
} }
alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done'
# Testing # Save HEAD commit hash to "snap" file in git dir
gitsnap() { echo Snapped $(git rev-parse HEAD | tee "$(git dir)/${1:-snap}") }
# Hard reset HEAD to commit in "snap"-file
gitsnaprestore() { git reset --hard $(cat "$(git dir)/${1:-snap}") }
gittestcommit() { touch file$((++i)) && git add . && git commit -m "Create file$i"; } # Remove list of tags local & remote
gitsnap() {
echo -n "Snapped "
echo $(git rev-parse HEAD) | tee "$(git dir)/${1:-snap}"
}
gitsnaprestore() {
git reset --hard $(cat "$(git dir)/${1:-snap}")
}
gitrmtag() { gitrmtag() {
declare -a refs declare -a refs
local index=1 local index=1
for tag in $@; do refs[index++]=":refs/tags/$tag"; done for tag in $@; do refs[index++]=":refs/tags/$tag"; done
git push origin "${refs[@]}" && git tag -d "$@" git push origin "${refs[@]}" && git tag -d "$@"
} }
# Rename a tag
gitretag() { gitretag() {
git push origin refs/tags/${1}:refs/tags/${2} :refs/tags/$1 && git tag -d $1 git push origin refs/tags/${1}:refs/tags/${2} :refs/tags/$1 && git tag -d $1
} }
# Repo management # Repo management {{{
gitinit() { gitinit() {
git init git init
git add . git add .
@ -97,18 +97,6 @@ gitbackup() {
cd $p cd $p
} }
gitremote() {
case "$1" in
http*) echo "git@$(echo "$1" | cut -d'/' -f3):$(echo "$1" | cut -d'/' -f4)/$(echo "$1" | cut -d'/' -f5)" ;;
*) test "$2" = "-" && 2=""
test "$3" = "cau" && 3="CAU-Kiel-Tech-Inf"
test "$3" = "btl" && 3="betweenthelinesev"
echo "git@git${1:-hub}.com:${3:-Xerus2000}/${2:-$(basename $PWD)}.git" ;;
esac
}
# Setting up repos
project() { project() {
cd $projects_dir cd $projects_dir
if [ -d $2 ] if [ -d $2 ]
@ -117,20 +105,30 @@ project() {
fi fi
} }
gitclone() { gitremote() {
case "$1" in
http*) echo "git@$(echo "$1" | cut -d'/' -f3):$(echo "$1" | cut -d'/' -f4)/$(echo "$1" | cut -d'/' -f5)" ;;
*) test "$3" = "cau" && 3="CAU-Kiel-Tech-Inf"
test "$3" = "btl" && 3="betweenthelinesev"
echo "git@git${1:-hub}.com:${3:-xerus2000}/${2:-$(basename $PWD)}.git" ;;
esac
}
gitclone() {
remote=$(gitremote "$@") remote=$(gitremote "$@")
echo $remote echo $remote
git clone $remote "${@:4}" git clone $remote "${@:4}"
cd "$2" cd "$(basename ${remote/.git})"
} }
gitfork() { gitfork() {
cd "$projects_dir/_forks" cd "$projects_dir/_forks"
gitclone hub "$1" gitclone hub "$1"
test "$2" && git remote add upstream "$(gitremote hub "$1" "$2")" test "$2" && git remote add upstream "$(gitremote hub "$1" "$2")"
git remote -v
} }
# sets this repo as origin and sets all branches upstream to their respective remote branch, if available # set repo as origin and set all branches upstream to their respective remote branch, if available
gitorigin() { gitorigin() {
git remote remove origin 2>/dev/null git remote remove origin 2>/dev/null
git remote add origin $(gitremote "$@") git remote add origin $(gitremote "$@")
@ -141,15 +139,16 @@ gitorigin() {
done done
} }
# sets this repo as upstream # set repo as upstream
gitupstream() { gitupstream() {
local name="${2:-upstream}" local name="${2:-upstream}"
git remote remove $name 2>/dev/null git remote remove $name 2>/dev/null
git remote add $name "$(git remote -v | grep origin | head -1 | cut -f2 | cut -d':' -f1):$1/$(git remote -v | grep origin | head -1 | cut -f2 | cut -d'/' -f2 | cut -d' ' -f1)" git remote add $name "$(git remote -v | grep origin | head -1 | cut -f2 | cut -d':' -f1):$1/$(git remote -v | grep origin | head -1 | cut -f2 | cut -d'/' -f2 | cut -d' ' -f1)"
git remote -v && git fetch $name || ( last=$? && echo "git fetch failed, aborting!" && return $last ) git remote -v && git fetch $name || ( last=$? && echo "git fetch failed, aborting!" && return $last )
} }
# }}}
# Rewriting history # Rewriting history {{{
# gets the AuthorDate of a given committish # gets the AuthorDate of a given committish
git-authordate() { git-authordate() {
@ -194,11 +193,11 @@ gitsquash() {
gitcommits -q $1 gitcommits -q $1
git reset --hard $1 git reset --hard $1
if [ $(git rev-list $2 --count) = 1 ]; then if [ $(git rev-list $2 --count) = 1 ]; then
git update-ref -d HEAD git update-ref -d HEAD
git add . git add .
git-withdate $1 commit -c $1 git-withdate $1 commit -c $1
else else
git reset -q $2 git reset -q $2
git add . git add .
git commit --amend git commit --amend
@ -220,7 +219,7 @@ gitcommits() {
done done
stashed="$(git rev-parse --show-toplevel)/.git/stashed-commits" stashed="$(git rev-parse --show-toplevel)/.git/stashed-commits"
if [ $1 ]; then if [ $1 ]; then
if [ $verbosity -eq 0 ] if [ $verbosity -eq 0 ]
then git rev-list --reverse HEAD...$1 >$stashed then git rev-list --reverse HEAD...$1 >$stashed
else git rev-list --reverse HEAD...$1 | tee $stashed else git rev-list --reverse HEAD...$1 | tee $stashed
@ -240,3 +239,7 @@ gitcommits() {
[ $aborted ] && echo "A problem was encountered. Fix it and run 'gitcommits' again to apply the remaining ${#rest} commits." [ $aborted ] && echo "A problem was encountered. Fix it and run 'gitcommits' again to apply the remaining ${#rest} commits."
fi fi
} }
# }}}
# Testing
gittestcommit() { touch file$((++i)) && git add . && git commit -m "Create file$i"; }