config/git: migrate log and caching shell aliases to bins

This commit is contained in:
xerus2000 2020-11-13 22:40:28 +01:00
parent ff04aba675
commit 2527d2630d
5 changed files with 19 additions and 18 deletions

View File

@ -24,7 +24,7 @@ git() {
command git "$@";
}
# Log local and upstream commits side by side - useful to check before forcing an action
# Log local and upstream commits side by side - useful to check when the history has been manipulated
glno() {
loc="$(git l --color=always "$@")"
upstream="$(git l --color=always $(git upstream) "$@")"
@ -36,23 +36,6 @@ glno() {
done
}
# Shortcuts
alias gcap!='git commit --all --amend --no-edit && git push --force-with-lease'
gitweek() { git my --after "$(date -d "Mon ${1:-1} weeks ago")" --before "$(date -d "Mon $(expr ${1:-1} - 1) weeks ago")" "${@:2}" }
# 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; }
# Caching
gitrecache() {
git rm --cached --quiet -r ${1:-.}
git add ${1:-.}
git status -s
}
gitrestore() {
git reset -- "$@"
git checkout -- "$@"
}
# BRANCHES
# Cleans up remote branches and removes branches where the remote-tracking branches got removed.
alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done'

4
.local/bin/git-child Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# Find a commit that follows the given one
# Second argument can be used to specify the search range - default HEAD
git log --reverse --ancestry-path --pretty=%H $1..${2:-HEAD} | head -1

4
.local/bin/git-rc Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# Restores the repository version of given files
git reset -- "$@"
git checkout -- "$@"

6
.local/bin/git-recache Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# Untracks and adds back all files (or the given path)
# Useful to remove tracked files after adding them to the gitignore
git rm --cached --quiet -r ${1:-.}
git add ${1:-.}
git status -s

4
.local/bin/git-week Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# Commits by myself throughout the current week
# Depends on git-my alias listing commits by myself
git my --after "$(date -d "Mon ${1:-1} weeks ago")" --before "$(date -d "Mon $(expr ${1:-1} - 1) weeks ago")" "${@:2}"