Created
January 29, 2019 15:37
-
-
Save allex/9d8fba5b7d66ba54a0bdb299a8bc232d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################### | |
## ALIASES | |
##################################################################### | |
[alias] | |
################################################# | |
## Simple / Short Aliases | |
################################################# | |
cl = clone | |
co = checkout | |
r = remote | |
mb = merge-base | |
################################################# | |
## Small Script Helpers | |
################################################# | |
# Convenience alias to resolve conflicted text files. | |
# | |
# $1 = "ours" or "theirs" | |
# $2 = The file or directory to resolve | |
# | |
# Use like: | |
# git resolve [ours|theirs] [file|directory] | |
resolve = "!f() { : git checkout ; git checkout --$1 -- $2 && git add -u $2; }; f" | |
# Move all untracked files in the working copy to another specified location. | |
# The hierarchy of the files moved is retained in the destination. | |
# | |
# $1 = The directory to move the untracked files to | |
move-untracked = !git ls-files --others --exclude-standard -z | cpio -pmd0 $1 | |
# Delete a tag locally and remotely in 1 operation. | |
# | |
# $1 = The remote name (e.g. origin) | |
# $2 = The tag name | |
delete-tag = "!f() { : git tag ; git push --delete $1 ${@:2}; git tag -d ${@:2}; }; f" | |
# Remove all untracked files and directories from the working copy. | |
# Be sure to run 'git status' first to confirm what this operation will remove! | |
delete-untracked = !git ls-files --others --exclude-standard | sed 's/.*/\"&\"/' | xargs rm -rfv | |
# Trim excess trailing whitespace from files in the staging area. | |
# Requires an external script. | |
trim-spaces = !git diff --cached --name-only | fix-whitespace | |
# Deletes a branch locally and remotely | |
# | |
# $1 = remote (e.g. origin) | |
# $2 = branch name locally & on specified remote | |
nuke = "!f() { : git branch ; git-nuke.sh \"$1\" \"$2\" ; }; f" | |
# Rename a branch locally and remotely | |
# | |
# $1 = remote | |
# $2 = current branch on remote | |
# $3 = new name | |
rename-branch = "!f() { : git branch ; git branch $3 $1/$2 && git push $1 $3 :$2 && git branch -D $3; }; f" | |
# Export working copy (similar to svn export) | |
export = checkout-index -f -a --prefix | |
cob = checkout --track @{upstream} -b | |
# The command `git reset --hard` does not support paths, however this alias will provide | |
# the functionally similar behavior. Note this will also delete untracked files (which | |
# git reset normally does not do). | |
# | |
# $1 = ref or revision to "reset" to | |
# $2 = path to reset (relative) | |
reset-path = "!f() { : git checkout ; rm -rf \"$2\" && git checkout \"$1\" -- \"$2\" ; }; f" | |
# Open any file on any branch. | |
# | |
# Example: | |
# | |
# $ git open origin/master Relative/Path/To/MyFile.txt | |
open = "!f() { : git show ; git-open-file.sh \"$1\" \"$2\"; }; f" | |
################################################# | |
## Index / Staging | |
################################################# | |
# Shortcut for 'checkout-index' | |
coi = checkout-index | |
# Shortcut for 'update-index' | |
ui = update-index | |
################################################# | |
## Stash | |
################################################# | |
# Apply stash with given index | |
# | |
# $1 = The index of the stash to apply | |
sa = "!f() { git stash apply stash@{$1}; }; f" | |
# Pop stash with given index | |
# | |
# $1 = The index of the stash to apply | |
sp = "!f() { git stash pop stash@{$1}; }; f" | |
# Shortcut for 'stash list' | |
sl = stash list | |
# Shortcut for 'stash save' | |
# | |
# $1 = Optional message for the stash | |
ss = stash save | |
################################################# | |
## Status / Working Copy | |
################################################# | |
# Short-form status | |
st = status -sb | |
# Short-form status; show all files in untracked directories | |
sta = status -sb -uall | |
# Show all local branches with ahead/behind status | |
stv = for-each-ref --format '%(HEAD) %(refname:short) %(color:bold blue)%(upstream:track)%(color:reset)' refs/heads | |
################################################# | |
## Branching | |
################################################# | |
# IMPLEMENTATION DETAIL, DO NOT USE | |
branch-sort = "!f() { : git branch ; git for-each-ref --sort=committerdate $1 --format='%(committerdate:short) -- %(authorname) -- %(refname:short)'; }; f" | |
# Short alias for 'branch' | |
br = branch | |
# List all branches (local and remote) matching an optional filter. | |
# | |
# $1 = (optional) Filter (e.g. origin/*) | |
# | |
# Example usage: | |
# $ git brl origin/* | |
brl = branch -a --list | |
# List all local branches sorted by last modified (commit) date | |
# in descending order. | |
brs = "!git branch-sort refs/heads/" | |
# Like 'brs', except functions on remote tracking branches. | |
# | |
# $1 = The remote name (e.g. origin) | |
# | |
# Example usage: | |
# $ git brsr origin | |
brsr = "!f() { : git branch ; git branch-sort refs/remotes/$1; }; f" | |
################################################# | |
## Log Viewing / Searching | |
################################################# | |
# IMPLEMENTATION DETAIL, DO NOT USE | |
long-log-base = log --abbrev-commit --decorate --format=format:'\ | |
%C(bold blue)%H%C(reset) %C(bold yellow)%d%C(reset)%n\ | |
> %C(dim white)Author: %an <%ae>%C(reset) [%C(dim white)%C(bold cyan)%ai%C(reset) %C(green)(%ar)%C(reset)]%n\ | |
> %C(dim white)Committer: %cn <%ce>%C(reset) [%C(dim white)%C(bold cyan)%ci%C(reset) %C(green)(%cr)%C(reset)]%n\ | |
%n\ | |
%C(white)%B%C(reset)' | |
# IMPLEMENTATION DETAIL, DO NOT USE | |
short-log-base = log --abbrev-commit --decorate --date=relative --format=format:'\ | |
%C(bold blue)%h%C(reset) | %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset) %C(dim white)%an%C(reset) - %C(white)%s%C(reset)' | |
# Logs with NO graph | |
l = !sh -c ": git log ; git short-log-base" # One-line logs | |
ls = !sh -c ": git log ; git short-log-base --first-parent" # One-line logs, first-parent only | |
l2 = !sh -c ": git log ; git long-log-base" # Detailed logs | |
ls2 = !sh -c ": git log ; git long-log-base --first-parent" # Detailed logs, first-parent only | |
lp = !sh -c ": git log ; git --no-pager short-log-base" # Same as 'l' but no pager. Useful for greping / pick-axing logs | |
lp2 = !sh -c ": git log ; git --no-pager long-log-base" # Same as 'l2' but no pager. Useful for grep and pickaxe | |
# Logs with GRAPH | |
lg = !sh -c ": git log ; git short-log-base --graph" # One-line logs | |
lg2 = !sh -c ": git log ; git long-log-base --graph" # Detailed logs | |
# Log just the commits on the branch compared to @{upstream} | |
lb = !git l @{upstream}.. | |
# Get a list of commits not pushed to @{push} | |
unpushed = !git l @{push}.. | |
# Reflog with pretty formatting. Shows: | |
# Short-SHA1 - HEAD@{n} - Relative Date - Description | |
rl = reflog --format=format:'%C(auto)%h %gd %C(bold green)(%cr)%C(reset) :: %gs' | |
# Display detailed log of tip commit. Useful for seeing the last commit you did. | |
lasts = !sh -c ": git log ; git --no-pager l2 -1" | |
# Like 'lasts', but also shows a list of files and status in the tip commit. | |
last = !sh -c ": git log ; git --no-pager l2 -1 --name-status" | |
# Format logs in such a way that you can pipe out to a file for | |
# release note purposes. | |
release-notes = log --pretty=format:'* %s %n%w(200,4,4)%b' | |
# Short alias for 'grep' that also has some formatting options | |
# to improve readability of results. | |
g = grep --break --heading --line-number | |
################################################# | |
## Push / Pull / Fetch | |
################################################# | |
# Short alias for 'fetch' | |
f = fetch | |
# Fetch from all remotes | |
fa = fetch --all | |
# Fetch from remote named 'origin' | |
fo = fetch origin | |
# Push HEAD, delete branch local & remote | |
# | |
# $1 = remote name | |
# $2 = branch name | |
pushdel = "!f() { : git push ; git-push-delete.sh \"$1\" \"$2\" ; }; f" | |
################################################# | |
## Diffing / Patching / Blaming / Tools | |
################################################# | |
# Short alias for 'format-patch' | |
fp = format-patch | |
# Short alias for 'mergetool' | |
mt = mergetool | |
# Short alias for 'diff' | |
d = diff | |
# Diff only staged files | |
dc = diff --cached | |
# Diff the current branch (HEAD) against its upstream tracking branch | |
db = "!f() { : git diff ; git diff $(git merge-base @{upstream} HEAD) ; }; f" | |
# Difftool HEAD against merge-base of the specified branch | |
dtb = "!f() { : git diff ; git dt $(git merge-base @{upstream} HEAD) ; }; f" | |
# Run difftool in "single-file" mode. For each file in the | |
# diff, the chosen diff tool will open once for each file. | |
# This is mainly provided to make diffing single files | |
# quicker, since git does not have to copy files being diffed | |
# to temp directories. | |
dts = difftool | |
# Same as 'dts' but for staged files only. | |
dtsc = difftool --cached | |
# Run difftool in directory mode. All files in the diff command | |
# will be displayed in the difftool all at once. This is more ideal | |
# when diffing lots of files, but can be slow when just diffing 1 file. | |
dt = difftool -d | |
# Same as 'dt' but for staged files only. | |
dtc = difftool --cached -d | |
# Display all conflicted files in the working copy. Useful to run | |
# during a rebase or merge. | |
conflicted = diff --name-only --diff-filter=U | |
# Use git log to format a patch file. Pipe this out to a file. | |
# | |
# $1 = Arguments to 'git log' (usually a range of commits to generate | |
# the patch for) | |
# | |
# Example: | |
# $ git patch HEAD^..HEAD > foo.patch | |
patch = log --pretty=email --patch-with-stat --reverse --full-index --binary | |
# Diff showing a list of modified files. | |
# | |
# $1 = (optional) Ref or SHA1 | |
# | |
# Example usage: | |
# $ git lsc HEAD^! | |
lsc = diff --name-status | |
# Diff the current branch (HEAD) against its upstream tracking branch | |
lscb = "!f() { : git diff ; git lsc $(git merge-base @{upstream} HEAD) ; }; f" | |
# Shortcuts for 'am' continue, abort, skip | |
ama = am --abort | |
amc = am --continue | |
ams = am --skip | |
# Convenient short alias for `git blame` with some nice default options | |
bl = blame --date=short -w --no-merges | |
# Stage all except whitespace | |
# | |
# From StackOverflow: | |
# http://stackoverflow.com/a/7149602/157971 | |
addw = !sh -c 'git diff -U0 -w --no-color "$@" | git apply --cached --ignore-whitespace --unidiff-zero' - | |
wsadd = "!sh -c 'git diff -- \"$@\" | git apply --cached --whitespace=fix; git co -- ${1-.} \"$@\"' -" | |
################################################# | |
## Commit / Merge / Rebase / Cherry Pick | |
################################################# | |
# Short alias for 'commit' | |
ci = commit | |
# Fixup Commit | |
cif = commit --fixup | |
# Squash Commit | |
cis = commit --squash | |
# Amend staged files to the previous commit. You can also | |
# use this to amend files explicitly. | |
# | |
# $1 = (optional) List of files or directories to amend the | |
# changes of. Leave blank to amend all staged files. | |
# | |
# Example (amend staged files): | |
# $ git amend | |
# | |
# Example (amend file explicitly): | |
# $ git amend my-file.cpp | |
amend = commit --amend --no-edit | |
# Stands for "All Amend". Works like "amend" but includes | |
# unstaged changes as well. Does not work with explicit | |
# parameters. | |
aamend = commit -a --amend --no-edit | |
# Merge with required commit message. | |
m = merge --edit | |
# Means "Merge Abort". Aborts an ongoing merge. | |
ma = merge --abort | |
# Commit a change to just a submodule with a preformatted | |
# commit message structure. | |
# | |
# $1 = Submodule to commit | |
# | |
# This command automates the commit message by providing a fixed | |
# subject line and the body will contain the diff output of the | |
# submodule itself. The submodule changes must be in the working | |
# copy and not staged. | |
# | |
# Example commit message: | |
# | |
# Updated Core Submodule | |
# | |
# Submodule Core eaedd3f..0721763: | |
# < Fixed ZA-123: Crash in rendering module | |
# < Merge 'develop' into 'master' | |
# | |
# You will be given an opportunity to edit the commit message after | |
# running this command. | |
smcommit = "!f() { git commit -m \"$(printf \"Updated $1 Submodule\n\n\"; git diff \"$1\")\" --edit -- $1; }; f" | |
# Perform a fast-forward merge only. | |
ff = merge --ff-only | |
# Short form of 'rebase'. | |
rb = rebase | |
# "Rebase Continue". Continues an ongoing rebase. | |
rbc = rebase --continue | |
# "Rebase Abort". Aborts an ongoing rebase. | |
rba = rebase --abort | |
# "Rebase Skip". Skips the current commit in an interactive rebase. | |
rbs = rebase --skip | |
# Short alias for 'cherry-pick'. | |
cp = cherry-pick | |
# "Cherry Pick Abort". Aborts ongoing cherry pick. | |
cpa = cherry-pick --abort | |
# "Cherry Pick Continue". Continues a cherry pick (when | |
# cherry picking a range of commits). | |
cpc = cherry-pick --continue | |
################################################# | |
## Submodule Helpers | |
################################################# | |
# Short alias for 'submodule' | |
sm = submodule | |
# Does a convenient submodule update command, which also initializes | |
# any submodules and is recursive. | |
# | |
# $1 = (optional) The submodule to update. If empty, updates all | |
# submodules. | |
smu = submodule update --init --recursive | |
# Like 'smu', but also specifies '--remote' option to force submodules | |
# to update to the latest commit on their respective branches. | |
smur = submodule update --init --recursive --remote | |
# Run any arbitrary command recursively across all submodules. | |
# | |
# Example (runs 'git fetch' recursively in all submodules): | |
# $ git run fetch | |
run = "!f() { git $@ && git submodule foreach --recursive git $@; }; f" | |
s = stash | |
##################################################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while read file | |
do | |
sed --in-place 's/[[:blank:]]\+$//' "$file"; | |
echo "Trimmed trailing whitespace in file: $file"; | |
done < "${1:-/dev/stdin}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment