Skip to content

Instantly share code, notes, and snippets.

@onigra
Created November 25, 2017 16:25
Show Gist options
  • Save onigra/649f3f02cbce7c58dab330d9a7e24dbe to your computer and use it in GitHub Desktop.
Save onigra/649f3f02cbce7c58dab330d9a7e24dbe to your computer and use it in GitHub Desktop.
git option normalization sample
#!/usr/local/bin/bash
#
# https://git-scm.com/docs/git-rev-parse#_parseopt
# https://github.com/git/git/blob/master/git-sh-setup.sh#L81L85
# https://twitter.com/sngworks/status/933953271487610880
# https://twitter.com/onigra_/status/934453258688479232
#
GIT_REBASE_OPTIONS_SPEC="
git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] [<upstream>] [<branch>]
git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>]
git-rebase --continue | --abort | --skip | --edit-todo
--
Available options are
v,verbose! display a diffstat of what changed upstream
q,quiet! be quiet. implies --no-stat
autostash automatically stash/stash pop before and after
fork-point use 'merge-base --fork-point' to refine upstream
onto=! rebase onto given branch instead of upstream
p,preserve-merges! try to recreate merges instead of ignoring them
s,strategy=! use the given merge strategy
no-ff! cherry-pick all commits, even if unchanged
m,merge! use merging strategies to rebase
i,interactive! let the user edit the list of commits to rebase
x,exec=! add exec lines after each commit of the editable list
k,keep-empty preserve empty commits during rebase
f,force-rebase! force rebase even if branch is up to date
X,strategy-option=! pass the argument through to the merge strategy
stat! display a diffstat of what changed upstream
n,no-stat! do not show diffstat of what changed upstream
verify allow pre-rebase hook to run
rerere-autoupdate allow rerere to update index with resolved conflicts
root! rebase all reachable commits up to the root(s)
autosquash move commits that begin with squash!/fixup! under -i
committer-date-is-author-date! passed to 'git am'
ignore-date! passed to 'git am'
signoff passed to 'git am'
whitespace=! passed to 'git apply'
ignore-whitespace! passed to 'git apply'
C=! passed to 'git apply'
S,gpg-sign? GPG-sign commits
Actions:
continue! continue
abort! abort and check out the original branch
skip! skip current patch and continue
edit-todo! edit the todo list during an interactive rebase
quit! abort but keep HEAD where it is
"
echo "$GIT_REBASE_OPTIONS_SPEC" | git rev-parse --parseopt --stuck-long -- "--con" #=> set -- --continue --
echo "$GIT_REBASE_OPTIONS_SPEC" | git rev-parse --parseopt --stuck-long -- "--ab" #=> set -- --abort --
echo "$GIT_REBASE_OPTIONS_SPEC" | git rev-parse --parseopt --stuck-long -- "--sk" #=> set -- --skip --
echo "$GIT_REBASE_OPTIONS_SPEC" | git rev-parse --parseopt --stuck-long -- "--ed" #=> set -- --edit-todo --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment