Add git fixup alias

This commit is contained in:
Marley Rae 2024-02-03 11:15:22 -08:00
parent 7ab0964083
commit 13138e6620

View file

@ -7,145 +7,146 @@ abbr -a g --position command git
################################################################################ ################################################################################
function git_develop_branch function git_develop_branch
command git rev-parse --git-dir &>/dev/null || return command git rev-parse --git-dir &>/dev/null || return
set -l branch set -l branch
for branch in dev devel develop development for branch in dev devel develop development
if command git show-ref -q --verify refs/heads/$branch if command git show-ref -q --verify refs/heads/$branch
echo $branch echo $branch
return 0 return 0
end
end end
end
echo develop echo develop
return 1 return 1
end end
function git_main_branch function git_main_branch
command git rev-parse --git-dir &>/dev/null || return command git rev-parse --git-dir &>/dev/null || return
set -l ref set -l ref
for ref in for ref in
refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master} refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}
if command git show-ref -q --verify $ref if command git show-ref -q --verify $ref
echo (basename $ref) echo (basename $ref)
return 0 return 0
end
end end
end
echo main echo main
return 1 return 1
end end
function git_current_branch function git_current_branch
set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null) set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null)
set -l ret $status set -l ret $status
if [ $ret -ne 0 ] if [ $ret -ne 0 ]
[ $ret -eq 128 ] && return # no git repo [ $ret -eq 128 ] && return # no git repo
set ref (git rev-parse --short HEAD 2>/dev/null) || return set ref (git rev-parse --short HEAD 2>/dev/null) || return
end end
echo (string replace "refs/heads/" "" $ref) echo (string replace "refs/heads/" "" $ref)
end end
################################################################################ ################################################################################
# Staging # # Staging #
################################################################################ ################################################################################
abbr -a ga --position command "git add" abbr -a ga --position command "git add"
abbr -a gaa --position command "git add --all" abbr -a gaa --position command "git add --all"
# Interactively stage parts of a file. # Interactively stage parts of a file.
abbr -a gapa --position command "git add --patch" abbr -a gapa --position command "git add --patch"
abbr -a gdl --position command "git diff" abbr -a gdl --position command "git diff"
abbr -a gdls --position command "git diff --staged" abbr -a gdls --position command "git diff --staged"
abbr -a gdlw --position command "git diff --word-diff" # show diff by word abbr -a gdlw --position command "git diff --word-diff" # show diff by word
abbr -a gdlsw --position command "git diff --staged --word-diff" abbr -a gdlsw --position command "git diff --staged --word-diff"
set exclude ":(exclude)package-lock.json" ":(exclude)*.lock" set exclude ":(exclude)package-lock.json" ":(exclude)*.lock"
function gd --wraps "git diff" function gd --wraps "git diff"
git diff $argv $exclude git diff $argv $exclude
end end
function gds --wraps "git diff" function gds --wraps "git diff"
git diff --staged $argv $exclude git diff --staged $argv $exclude
end end
function gdw --wraps "git diff" function gdw --wraps "git diff"
git diff --word-diff $argv $exclude git diff --word-diff $argv $exclude
end end
function gdsw --wraps "git diff" function gdsw --wraps "git diff"
git diff --staged --word-diff $argv $exclude git diff --staged --word-diff $argv $exclude
end end
abbr -a gst --position command "git status" abbr -a gst --position command "git status"
abbr -a gsts --position command "git status --short" abbr -a gsts --position command "git status --short"
################################################################################ ################################################################################
# Committing # # Committing #
################################################################################ ################################################################################
abbr -a gc --position command "git commit" abbr -a gc --position command "git commit"
abbr -a "gc!" --position command "git commit --amend" abbr -a "gc!" --position command "git commit --amend"
abbr -a "gcn!" --position command "git commit --no-edit --amend" abbr -a "gcn!" --position command "git commit --no-edit --amend"
abbr -a gca --position command "git add --all && git commit" abbr -a gca --position command "git add --all && git commit"
abbr -a "gca!" --position command "git commit -a --amend" abbr -a "gca!" --position command "git commit -a --amend"
abbr -a "gcan!" --position command "git commit -a --no-edit --amend" abbr -a "gcan!" --position command "git commit -a --no-edit --amend"
abbr -a gcam --position command "git commit -a -m" abbr -a gcam --position command "git commit -a -m"
abbr -a gcmsg --position command "git commit -m" abbr -a gcmsg --position command "git commit -m"
abbr -a gcfu --position command "git commit --fixup"
abbr -a grev --position command "git revert" abbr -a grev --position command "git revert"
# Update the last commit with all staged changes. # Update the last commit with all staged changes.
abbr -a gu --position command "git commit --amend" abbr -a gu --position command "git commit --amend"
abbr -a "gu!" --position command "git commit --amend --no-edit" abbr -a "gu!" --position command "git commit --amend --no-edit"
# Update the last commit with all local changes. # Update the last commit with all local changes.
abbr -a gua --position command "git add --all && git commit --amend" abbr -a gua --position command "git add --all && git commit --amend"
abbr -a "gua!" --position command "git add --all && git commit --amend --no-edit" abbr -a "gua!" --position command "git add --all && git commit --amend --no-edit"
################################################################################ ################################################################################
# Working Dir & Index Manipulation # # Working Dir & Index Manipulation #
################################################################################ ################################################################################
abbr -a gco --position command "git checkout" abbr -a gco --position command "git checkout"
abbr -a grt --position command "git reset" abbr -a grt --position command "git reset"
# grt <commit> -- [<path>] - undo <commit> but keep changes in working dir. # grt <commit> -- [<path>] - undo <commit> but keep changes in working dir.
abbr -a grts --position command "git reset --soft" abbr -a grts --position command "git reset --soft"
# Undo commits and stage their changes. # Undo commits and stage their changes.
abbr -a grs --position command "git restore --worktree" abbr -a grs --position command "git restore --worktree"
# grs <unstaged-path> - revert local changes for <unstaged-path>. # grs <unstaged-path> - revert local changes for <unstaged-path>.
# (--worktree is the default behavior, but included here for clarity). # (--worktree is the default behavior, but included here for clarity).
abbr -a grss --position command "git restore --worktree --source" abbr -a grss --position command "git restore --worktree --source"
# grss <commit> <unstaged-path> - revert <unstaged-path> to <commit>"s version. # grss <commit> <unstaged-path> - revert <unstaged-path> to <commit>"s version.
abbr -a grst --position command "git restore --staged" abbr -a grst --position command "git restore --staged"
# grst <staged-path> - unstage <staged-path> # grst <staged-path> - unstage <staged-path>
abbr -a grsts --position command "git restore --staged --source" abbr -a grsts --position command "git restore --staged --source"
# See grss, but for <staged-path>s. # See grss, but for <staged-path>s.
abbr -a grsa --position command "git restore --worktree --staged" abbr -a grsa --position command "git restore --worktree --staged"
# grsa <path> - discard all changes for <path>, both staged and unstaged. # grsa <path> - discard all changes for <path>, both staged and unstaged.
abbr -a grsas --position command "git restore --worktree --staged --source" abbr -a grsas --position command "git restore --worktree --staged --source"
abbr -a grm --position command "git rm" abbr -a grm --position command "git rm"
# Remove paths from index & working dir. # Remove paths from index & working dir.
abbr -a grmc --position command "git rm --cached" abbr -a grmc --position command "git rm --cached"
# Unstage & remove only from index; leave in working dir. # Unstage & remove only from index; leave in working dir.
# grmc <path> - where <path> is already tracked: stages the removal of <path> # grmc <path> - where <path> is already tracked: stages the removal of <path>
abbr -a gsta --position command "git stash push" abbr -a gsta --position command "git stash push"
# Save changes; add --message <message> to label stash. # Save changes; add --message <message> to label stash.
abbr -a gstaa --position command "git stash push --include-untracked" abbr -a gstaa --position command "git stash push --include-untracked"
@ -156,18 +157,17 @@ abbr -a gstas --position command "git stash show --text"
# --text treats all files as text. # --text treats all files as text.
function gwip function gwip
git add -A git add -A
git rm (git ls-files --deleted) 2> /dev/null git rm (git ls-files --deleted) 2>/dev/null
git commit --no-verify --no-gpg-sign --message "🚧 --wip-- [skip ci]" git commit --no-verify --no-gpg-sign --message "🚧 --wip-- [skip ci]"
end end
function gunwip function gunwip
git rev-list --max-count=1 --format="%s" HEAD | \ git rev-list --max-count=1 --format="%s" HEAD | grep -q "🚧 --wip--" \
grep -q "🚧 --wip--" \ && git reset HEAD~1
&& git reset HEAD~1
end end
abbr -a gcl --position command "git clean -f" abbr -a gcl --position command "git clean -f"
# Remove unknown (untracked and unignored) files. # Remove unknown (untracked and unignored) files.
abbr -a gcldr --position command "git clean --dry-run" abbr -a gcldr --position command "git clean --dry-run"
@ -176,26 +176,26 @@ abbr -a gcldr --position command "git clean --dry-run"
# Branches # # Branches #
################################################################################ ################################################################################
abbr -a gb --position command "git branch" abbr -a gb --position command "git branch"
abbr -a gcb --position command "git checkout -b" abbr -a gcb --position command "git checkout -b"
abbr -a gcm --position command "git checkout $(git_main_branch)" abbr -a gcm --position command "git checkout $(git_main_branch)"
abbr -a gcd --position command "git checkout $(git_develop_branch)" abbr -a gcd --position command "git checkout $(git_develop_branch)"
abbr -a gm --position command "git merge" abbr -a gm --position command "git merge"
abbr -a gmtl --position command "git mergetool --no-prompt" abbr -a gmtl --position command "git mergetool --no-prompt"
abbr -a gma --position command "git merge --abort" abbr -a gma --position command "git merge --abort"
################################################################################ ################################################################################
# History Manipulation # # History Manipulation #
################################################################################ ################################################################################
abbr -a gbs --position command "git bisect" abbr -a gbs --position command "git bisect"
abbr -a gbsb --position command "git bisect bad" abbr -a gbsb --position command "git bisect bad"
abbr -a gbsg --position command "git bisect good" abbr -a gbsg --position command "git bisect good"
abbr -a gbsr --position command "git bisect reset" abbr -a gbsr --position command "git bisect reset"
abbr -a gbss --position command "git bisect start" abbr -a gbss --position command "git bisect start"
abbr -a grb --position command "git rebase" abbr -a grb --position command "git rebase"
abbr -a grbi --position command "git rebase --interactive" abbr -a grbi --position command "git rebase --interactive"
abbr -a grbo --position command "git rebase --onto" abbr -a grbo --position command "git rebase --onto"
abbr -a grba --position command "git rebase --abort" abbr -a grba --position command "git rebase --abort"
@ -208,36 +208,36 @@ abbr -a grbm --position command "git rebase $(git_main_branch)"
# Interaction with Remote # # Interaction with Remote #
################################################################################ ################################################################################
abbr -a gp --position command "git push" abbr -a gp --position command "git push"
abbr -a gpv --position command "git push -v" abbr -a gpv --position command "git push -v"
abbr -a gpd --position command "git push --dry-run" abbr -a gpd --position command "git push --dry-run"
abbr -a gpf --position command "git push --force-with-lease --force-if-includes" abbr -a gpf --position command "git push --force-with-lease --force-if-includes"
abbr -a gpfv --position command "git push --force-with-lease --force-if-includes -v" abbr -a gpfv --position command "git push --force-with-lease --force-if-includes -v"
abbr -a "gpf!" --position command "git push --force" abbr -a "gpf!" --position command "git push --force"
abbr -a "gpfv!" --position command "git push --force -v" abbr -a "gpfv!" --position command "git push --force -v"
abbr -a gf --position command "git fetch" abbr -a gf --position command "git fetch"
abbr -a gfa --position command "git fetch --all --prune" abbr -a gfa --position command "git fetch --all --prune"
# Fetch all & remove invalid remote refs. # Fetch all & remove invalid remote refs.
abbr -a gpl --position command "git pull" abbr -a gpl --position command "git pull"
abbr -a gplr --position command "git pull --rebase" abbr -a gplr --position command "git pull --rebase"
################################################################################ ################################################################################
# Logs # # Logs #
################################################################################ ################################################################################
# Current branch. # Current branch.
abbr -a gl --position command "git log --pretty=lc --graph" abbr -a gl --position command "git log --pretty=lc --graph"
abbr -a glo --position command "git log --pretty=lo --graph --date=human" abbr -a glo --position command "git log --pretty=lo --graph --date=human"
abbr -a gls --position command "git log --pretty=lo --graph --date=human --simplify-by-decoration" abbr -a gls --position command "git log --pretty=lo --graph --date=human --simplify-by-decoration"
abbr -a glf --position command "git log --pretty=lf --graph" abbr -a glf --position command "git log --pretty=lf --graph"
abbr -a gld --position command "git log --pretty=lf --graph --cc --stat" abbr -a gld --position command "git log --pretty=lf --graph --cc --stat"
abbr -a glp --position command "git log --pretty=lf --graph --cc --patch" abbr -a glp --position command "git log --pretty=lf --graph --cc --patch"
# All branches on all remotes. # All branches on all remotes.
abbr -a gla --position command "git log --pretty=lc --graph --all" abbr -a gla --position command "git log --pretty=lc --graph --all"
abbr -a glao --position command "git log --pretty=lo --graph --all --date=human" abbr -a glao --position command "git log --pretty=lo --graph --all --date=human"
abbr -a glas --position command "git log --pretty=lo --graph --all --date=human --simplify-by-decoration" abbr -a glas --position command "git log --pretty=lo --graph --all --date=human --simplify-by-decoration"
abbr -a glaf --position command "git log --pretty=lf --graph --all" abbr -a glaf --position command "git log --pretty=lf --graph --all"
@ -249,9 +249,9 @@ abbr -a glap --position command "git log --pretty=lf --graph --all --cc --patch"
################################################################################ ################################################################################
function gprevision -a N path function gprevision -a N path
git checkout \ git checkout \
(git log --online $path | awk -v commit="$N" "FNR == -commit+1 {print $N}") \ (git log --online $path | awk -v commit="$N" "FNR == -commit+1 {print $N}") \
$path $path
end end
# gprevision <N> <path> # gprevision <N> <path>
# Checkout the <N>th revision (counting backwards from HEAD) of <path>. # Checkout the <N>th revision (counting backwards from HEAD) of <path>.
@ -260,7 +260,7 @@ end
# gprevision -1 example.txt # gprevision -1 example.txt
function gnevermind function gnevermind
reset --hard HEAD && git clean -df reset --hard HEAD && git clean -df
end end
################################################################################ ################################################################################