2024-01-28 21:46:15 -08:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
|
|
|
|
abbr -a g --position command git
|
|
|
|
|
|
|
|
################################################################################
|
2024-01-31 17:32:03 -08:00
|
|
|
# Functions #
|
2024-01-28 21:46:15 -08:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
function git_develop_branch
|
2024-02-03 11:15:22 -08:00
|
|
|
command git rev-parse --git-dir &>/dev/null || return
|
|
|
|
set -l branch
|
|
|
|
|
|
|
|
for branch in dev devel develop development
|
|
|
|
if command git show-ref -q --verify refs/heads/$branch
|
|
|
|
echo $branch
|
|
|
|
return 0
|
|
|
|
end
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
echo develop
|
|
|
|
return 1
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
function git_main_branch
|
2024-02-03 11:15:22 -08:00
|
|
|
command git rev-parse --git-dir &>/dev/null || return
|
|
|
|
set -l ref
|
|
|
|
|
|
|
|
for ref in
|
|
|
|
refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}
|
|
|
|
if command git show-ref -q --verify $ref
|
|
|
|
echo (basename $ref)
|
|
|
|
return 0
|
|
|
|
end
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
echo main
|
|
|
|
return 1
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
function git_current_branch
|
2024-02-03 11:15:22 -08:00
|
|
|
set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null)
|
|
|
|
set -l ret $status
|
2024-01-28 21:46:15 -08:00
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
if [ $ret -ne 0 ]
|
|
|
|
[ $ret -eq 128 ] && return # no git repo
|
|
|
|
set ref (git rev-parse --short HEAD 2>/dev/null) || return
|
|
|
|
end
|
2024-01-28 21:46:15 -08:00
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
echo (string replace "refs/heads/" "" $ref)
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Staging #
|
|
|
|
################################################################################
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a ga --position command "git add"
|
|
|
|
abbr -a gaa --position command "git add --all"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
|
|
|
# Interactively stage parts of a file.
|
|
|
|
abbr -a gapa --position command "git add --patch"
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gdl --position command "git diff"
|
|
|
|
abbr -a gdls --position command "git diff --staged"
|
|
|
|
abbr -a gdlw --position command "git diff --word-diff" # show diff by word
|
2024-01-30 19:28:48 -08:00
|
|
|
abbr -a gdlsw --position command "git diff --staged --word-diff"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
2024-01-30 19:28:48 -08:00
|
|
|
set exclude ":(exclude)package-lock.json" ":(exclude)*.lock"
|
|
|
|
|
|
|
|
function gd --wraps "git diff"
|
2024-02-03 11:15:22 -08:00
|
|
|
git diff $argv $exclude
|
2024-01-30 19:28:48 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
function gds --wraps "git diff"
|
2024-02-03 11:15:22 -08:00
|
|
|
git diff --staged $argv $exclude
|
2024-01-30 19:28:48 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
function gdw --wraps "git diff"
|
2024-02-03 11:15:22 -08:00
|
|
|
git diff --word-diff $argv $exclude
|
2024-01-30 19:28:48 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
function gdsw --wraps "git diff"
|
2024-02-03 11:15:22 -08:00
|
|
|
git diff --staged --word-diff $argv $exclude
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
2024-02-03 13:14:55 -08:00
|
|
|
abbr -a gst --position command "git status --short --branch"
|
|
|
|
abbr -a gstl --position command "git status"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Committing #
|
|
|
|
################################################################################
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gc --position command "git commit"
|
|
|
|
abbr -a "gc!" --position command "git commit --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 commit -a --amend"
|
2024-01-28 21:46:15 -08:00
|
|
|
abbr -a "gcan!" --position command "git commit -a --no-edit --amend"
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gcam --position command "git commit -a -m"
|
|
|
|
abbr -a gcmsg --position command "git commit -m"
|
|
|
|
abbr -a gcfu --position command "git commit --fixup"
|
2024-01-30 19:28:48 -08:00
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grev --position command "git revert"
|
2024-01-30 19:28:48 -08:00
|
|
|
|
|
|
|
# Update the last commit with all staged changes.
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gu --position command "git commit --amend"
|
|
|
|
abbr -a "gu!" --position command "git commit --amend --no-edit"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
2024-01-30 19:28:48 -08:00
|
|
|
# Update the last commit with all local changes.
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gua --position command "git add --all && git commit --amend"
|
|
|
|
abbr -a "gua!" --position command "git add --all && git commit --amend --no-edit"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Working Dir & Index Manipulation #
|
|
|
|
################################################################################
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gco --position command "git checkout"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grt --position command "git reset"
|
2024-01-28 21:46:15 -08:00
|
|
|
# grt <commit> -- [<path>] - undo <commit> but keep changes in working dir.
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grts --position command "git reset --soft"
|
2024-01-28 21:46:15 -08:00
|
|
|
# Undo commits and stage their changes.
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grs --position command "git restore --worktree"
|
2024-01-28 21:46:15 -08:00
|
|
|
# grs <unstaged-path> - revert local changes for <unstaged-path>.
|
|
|
|
# (--worktree is the default behavior, but included here for clarity).
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grss --position command "git restore --worktree --source"
|
2024-01-28 21:46:15 -08:00
|
|
|
# grss <commit> <unstaged-path> - revert <unstaged-path> to <commit>"s version.
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grst --position command "git restore --staged"
|
2024-01-28 21:46:15 -08:00
|
|
|
# grst <staged-path> - unstage <staged-path>
|
|
|
|
|
|
|
|
abbr -a grsts --position command "git restore --staged --source"
|
|
|
|
# See grss, but for <staged-path>s.
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grsa --position command "git restore --worktree --staged"
|
2024-01-28 21:46:15 -08:00
|
|
|
# grsa <path> - discard all changes for <path>, both staged and unstaged.
|
|
|
|
|
|
|
|
abbr -a grsas --position command "git restore --worktree --staged --source"
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grm --position command "git rm"
|
2024-01-28 21:46:15 -08:00
|
|
|
# Remove paths from index & working dir.
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grmc --position command "git rm --cached"
|
2024-01-28 21:46:15 -08:00
|
|
|
# Unstage & remove only from index; leave in working dir.
|
|
|
|
# grmc <path> - where <path> is already tracked: stages the removal of <path>
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gsta --position command "git stash push"
|
2024-01-28 21:46:15 -08:00
|
|
|
# Save changes; add --message <message> to label stash.
|
|
|
|
|
|
|
|
abbr -a gstaa --position command "git stash push --include-untracked"
|
|
|
|
abbr -a gstap --position command "git stash pop" # retrieve changes
|
|
|
|
abbr -a gstal --position command "git stash list" # list stashes
|
|
|
|
|
|
|
|
abbr -a gstas --position command "git stash show --text"
|
|
|
|
# --text treats all files as text.
|
|
|
|
|
|
|
|
function gwip
|
2024-02-03 11:15:22 -08:00
|
|
|
git add -A
|
|
|
|
git rm (git ls-files --deleted) 2>/dev/null
|
|
|
|
git commit --no-verify --no-gpg-sign --message "🚧 --wip-- [skip ci]"
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
2024-01-31 17:32:03 -08:00
|
|
|
function gunwip
|
2024-02-03 11:15:22 -08:00
|
|
|
git rev-list --max-count=1 --format="%s" HEAD | grep -q "🚧 --wip--" \
|
|
|
|
&& git reset HEAD~1
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gcl --position command "git clean -f"
|
2024-01-28 21:46:15 -08:00
|
|
|
# Remove unknown (untracked and unignored) files.
|
|
|
|
|
|
|
|
abbr -a gcldr --position command "git clean --dry-run"
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Branches #
|
|
|
|
################################################################################
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gb --position command "git branch"
|
|
|
|
abbr -a gcb --position command "git checkout -b"
|
|
|
|
abbr -a gcm --position command "git checkout $(git_main_branch)"
|
|
|
|
abbr -a gcd --position command "git checkout $(git_develop_branch)"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gm --position command "git merge"
|
2024-01-28 21:46:15 -08:00
|
|
|
abbr -a gmtl --position command "git mergetool --no-prompt"
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gma --position command "git merge --abort"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# History Manipulation #
|
|
|
|
################################################################################
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gbs --position command "git bisect"
|
2024-01-28 21:46:15 -08:00
|
|
|
abbr -a gbsb --position command "git bisect bad"
|
|
|
|
abbr -a gbsg --position command "git bisect good"
|
|
|
|
abbr -a gbsr --position command "git bisect reset"
|
|
|
|
abbr -a gbss --position command "git bisect start"
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a grb --position command "git rebase"
|
2024-01-31 20:26:53 -08:00
|
|
|
abbr -a grbi --position command "git rebase --interactive"
|
|
|
|
abbr -a grbo --position command "git rebase --onto"
|
|
|
|
abbr -a grba --position command "git rebase --abort"
|
|
|
|
abbr -a grbc --position command "git rebase --continue"
|
|
|
|
abbr -a grbs --position command "git rebase --skip"
|
|
|
|
abbr -a grbd --position command "git rebase $(git_develop_branch)"
|
|
|
|
abbr -a grbm --position command "git rebase $(git_main_branch)"
|
|
|
|
|
2024-01-28 21:46:15 -08:00
|
|
|
################################################################################
|
|
|
|
# Interaction with Remote #
|
|
|
|
################################################################################
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gp --position command "git push"
|
|
|
|
abbr -a gpv --position command "git push -v"
|
|
|
|
abbr -a gpd --position command "git push --dry-run"
|
|
|
|
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 "gpf!" --position command "git push --force"
|
2024-01-28 21:46:15 -08:00
|
|
|
abbr -a "gpfv!" --position command "git push --force -v"
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gf --position command "git fetch"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gfa --position command "git fetch --all --prune"
|
2024-01-28 21:46:15 -08:00
|
|
|
# Fetch all & remove invalid remote refs.
|
|
|
|
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gpl --position command "git pull"
|
|
|
|
abbr -a gplr --position command "git pull --rebase"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Logs #
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Current branch.
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gl --position command "git log --pretty=lc --graph"
|
|
|
|
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 glf --position command "git log --pretty=lf --graph"
|
|
|
|
abbr -a gld --position command "git log --pretty=lf --graph --cc --stat"
|
|
|
|
abbr -a glp --position command "git log --pretty=lf --graph --cc --patch"
|
2024-01-28 21:46:15 -08:00
|
|
|
|
|
|
|
# All branches on all remotes.
|
2024-02-03 11:15:22 -08:00
|
|
|
abbr -a gla --position command "git log --pretty=lc --graph --all"
|
2024-01-28 21:46:15 -08:00
|
|
|
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 glaf --position command "git log --pretty=lf --graph --all"
|
|
|
|
abbr -a glad --position command "git log --pretty=lf --graph --all --cc --stat"
|
|
|
|
abbr -a glap --position command "git log --pretty=lf --graph --all --cc --patch"
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Shortcuts to Feel Smart #
|
|
|
|
################################################################################
|
|
|
|
|
2024-01-29 19:54:57 -08:00
|
|
|
function gprevision -a N path
|
2024-02-03 11:15:22 -08:00
|
|
|
git checkout \
|
|
|
|
(git log --online $path | awk -v commit="$N" "FNR == -commit+1 {print $N}") \
|
|
|
|
$path
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
# gprevision <N> <path>
|
|
|
|
# Checkout the <N>th revision (counting backwards from HEAD) of <path>.
|
|
|
|
#
|
|
|
|
# e.g. to checkout the last version of example.txt:
|
|
|
|
# gprevision -1 example.txt
|
|
|
|
|
|
|
|
function gnevermind
|
2024-02-03 11:15:22 -08:00
|
|
|
reset --hard HEAD && git clean -df
|
2024-01-28 21:46:15 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Notes #
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# A note on reset, restore, and revert, paraphrased from `man git`, plus my own
|
|
|
|
# on `rm`:
|
|
|
|
#
|
|
|
|
# revert - make a new commit that reverts a previous commit.
|
|
|
|
# restore - undo uncommitted changes in the working tree.
|
|
|
|
# reset - update the branch and change commit history.
|
|
|
|
# rm - same as system rm; remove files, either from git's knowledge, the working
|
|
|
|
# directory, or both.
|
|
|
|
#
|
|
|
|
# These are not a description of the *possible* uses, rather a narrowing of the
|
|
|
|
# *intended* uses.
|
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
|
|
|
# PATH VALUES:
|
|
|
|
# :/ - all files within the root of the working tree, so all files in the repo,
|
|
|
|
# a la git add's --all option.
|