Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1449 lines
56KB

  1. # -*- mode: gitconfig; -*-
  2. # vim: set filetype=gitconfig:
  3. ##
  4. # GitAlias.com file of many git alias items, including shortcuts, helpers, workflows, etc.
  5. #
  6. #
  7. # ## Usage
  8. #
  9. # Typical usage for a typical user:
  10. #
  11. # * Save this file as a dot file in your home directory: `~/.gitalias.txt`
  12. #
  13. # * Edit your git config dot file in your home directory such as `~/.gitconfig`
  14. #
  15. # * Include the path to this file.
  16. #
  17. # Example file `~/.gitconfig` with an entry to include the file `~/.gitalias.txt`:
  18. #
  19. # [include]
  20. # path = gitalias.txt
  21. #
  22. #
  23. # ## Usage for older git versions
  24. #
  25. # If you use an older version of git that does not have git config "include" capability,
  26. # or if you prefer more control, then you can simply copy/paste anything you like from
  27. # this file to your own git config file.
  28. #
  29. #
  30. # ## Customization
  31. #
  32. # If you want to use this file, and also want to change some of the items,
  33. # then one way is to use your git config file to include this gitalias file,
  34. # and also define your own alias items; a later alias takes precedence.
  35. #
  36. # Example file `~/.gitconfig` item to include the file `~/.gitalias.txt`:
  37. #
  38. # [include]
  39. # path = ~/.gitconfig.d/gitalias.txt
  40. # [alias]
  41. # l = log --graph --oneline
  42. #
  43. #
  44. # ## Links
  45. #
  46. # * [GitAlias.com website](http://gitlias.com)
  47. # * [GitAlias GitHub](https://github.com/gitalias)
  48. # * [Git Basics - Git Aliases](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases)
  49. # * [Git Basics - Tips and Tricks](https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks)
  50. #
  51. # ## Tracking
  52. #
  53. # * Package: gitalias
  54. # * Version: 23.1.0
  55. # * Created: 2016-06-17
  56. # * Updated: 2020-03-01
  57. # * License: GPL
  58. # * Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)
  59. ##
  60. [alias]
  61. ##
  62. # One letter alias for our most frequent commands.
  63. #
  64. # Guidelines: these aliases do not use options, because we want
  65. # these aliases to be easy to compose and use in many ways.
  66. ##
  67. a = add
  68. b = branch
  69. c = commit
  70. d = diff
  71. f = fetch
  72. g = grep
  73. l = log
  74. m = merge
  75. o = checkout
  76. p = pull
  77. r = remote
  78. s = status
  79. w = whatchanged
  80. ##
  81. # Short aliases for our frequent commands.
  82. #
  83. # Guidelines:
  84. #
  85. # * Generally speaking, the alias should be in the same
  86. # order as the command name followed by its options.
  87. #
  88. # * Right: fb = foo --bar
  89. # * Wrong: bf = foo --bar
  90. ##
  91. ### add ###
  92. # add all
  93. aa = add --all
  94. # add by patch - looks at each change, and asks if we want to put it in the repo.
  95. ap = add --patch
  96. # add just the files that are updated.
  97. au = add --update
  98. ### branch ###
  99. # branch description
  100. bd = !"git config branch.$(git rev-parse --abbrev-ref HEAD 2>/dev/null).description"
  101. # bra nch - edit the description
  102. be = branch --edit-description
  103. # branch and only list branches whose tips are reachable from the specified commit (HEAD if not specified).
  104. bm = branch --merged
  105. # branch and only list branches whose tips are not reachable from the specified commit (HEAD if not specified).
  106. bnm = branch --no-merged
  107. ### commit ###
  108. # commit - amend the tip of the current branch rather than creating a new commit.
  109. ca = commit --amend
  110. # commit - amend the tip of the current branch, and edit the message.
  111. cam = commit --amend --message
  112. # commit - amend the tip of the current branch, and do not edit the message.
  113. cane = commit --amend --no-edit
  114. # commit interactive
  115. ci = commit --interactive
  116. # commit with a message
  117. cm = commit --message
  118. ### checkout ###
  119. # checkout - update the working tree to match a branch or paths. [same as "o" for "out"]
  120. co = checkout
  121. con = checkout --no-guess
  122. ### cherry-pick ###
  123. # cherry-pick - apply the changes introduced by some existing commits; useful for moving small chunks of code between branches.
  124. cp = cherry-pick
  125. # cherry-pick - abort the picking process
  126. cpa = cherry-pick --abort
  127. # cherry-pick - continue the picking process
  128. cpc = cherry-pick --continue
  129. # cherry-pick without making a commit, and when when recording the commit, append a line that says "(cherry picked from commit ...)"
  130. cp-nx = cherry-pick --no-commit -x
  131. ### diff ###
  132. # diff - show changes not yet staged
  133. dc = diff --cached
  134. # diff - show changes about to be commited
  135. ds = diff --staged
  136. # diff - show changes but by word, not line
  137. dw = diff --word-diff
  138. # diff deep - show changes with our preferred options. Also aliased as `diff-deep`.
  139. dd = diff --check --dirstat --find-copies --find-renames --histogram --color
  140. ### clean ###
  141. # clean everything to be pristine
  142. cleanest = clean -ffdx
  143. ### grep ###
  144. # grep i.e. search for text
  145. g = grep
  146. # grep - show line number
  147. gl = grep --line-number
  148. # grep group - search with our preferred options. Also aliased as `grep-group`.
  149. gg = grep --break --heading --line-number --color
  150. ### log ###
  151. # log with a text-based graphical representation of the commit history.
  152. lg = log --graph
  153. # log with one line per item.
  154. lo = log --oneline
  155. # log with patch generation.
  156. lp = log --patch
  157. # log with first parent, useful for team branch that only accepts pull requests
  158. lfp = log --first-parent
  159. # log with items appearing in topological order, i.e. descendant commits are shown before their parents.
  160. lt = log --topo-order
  161. # log like - we like this summarization our key performance indicators. Also aliased as `log-like`.
  162. ll = log --graph --topo-order --date=short --abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn]%Creset %Cblue%G?%Creset'
  163. # log like long - we like this summarization our key performance indicators. Also aliased as `log-like-long`.
  164. lll = log --graph --topo-order --date=iso8601-strict --no-abbrev-commit --abbrev=40 --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn <%ce>]%Creset %Cblue%G?%Creset'
  165. ## ls-files ##
  166. # ls-files - show information about files in the index and the working tree; like Unix "ls" command.
  167. ls = ls-files
  168. # ls-ignored - list files that git has ignored.
  169. ls-ignored = ls-files --others --i --exclude-standard
  170. ### merge ###
  171. # merge but without autocommit, and with a commit even if the merge resolved as a fast-forward.
  172. me = merge --no-commit --no-ff
  173. ### pull ###
  174. # pull if a merge can be resolved as a fast-forward, otherwise fail.
  175. pf = pull --ff-only
  176. # pull with rebase - to provide a cleaner, linear, bisectable history.
  177. #
  178. # To automatically do "pull --rebase" everywhere:
  179. #
  180. # git config --global pull.rebase true
  181. #
  182. # To automatically do "pull --rebase" for any branch based on master:
  183. #
  184. # git config branch.master.rebase true
  185. #
  186. # To automatically do "pull --rebase" for any newly-created branches:
  187. #
  188. # git config --global branch.autosetuprebase always
  189. #
  190. # To integrate changes between branches, you can merge or rebase.
  191. #
  192. # When we use "git pull", git does a fetch then a merge.
  193. # If we've made changes locally and someone else has pushed changes
  194. # to our git host then git will automatically merge these together
  195. # and create a merge commit that looks like this in the history:
  196. #
  197. # 12345678 - Merge branch 'foo' of bar into master
  198. #
  199. # When we use "git pull --rebase", git does a fetch then a rebase.
  200. # A rebase resets the HEAD of your local branch to be the same as
  201. # the remote HEAD, then replays your local commits back into repo.
  202. # This means you don't get any noisy merge messages in your history.
  203. # This gives us a linear history, and also helps with git bisect.
  204. #
  205. pr = pull --rebase
  206. # pp - pull with rebase preserve of merge commits
  207. #
  208. # See https://stackoverflow.com/questions/21364636/git-pull-rebase-preserve-merges
  209. #
  210. # You should only rebase if you know (in a sort of general sense)
  211. # what you are doing, and if you do know what you are doing, then you
  212. # would probably prefer a merge-preserving rebase as a general rule.
  213. #
  214. # Although by the time you've decided that rebasing is a good idea,
  215. # you will probably find that a history that has its own embedded
  216. # branch-and-merge-points is not necessarily the correct "final
  217. # rewritten history".
  218. #
  219. # That is, if it's appropriate to do a rebase at all, it's at least fairly
  220. # likely that the history to be rebased is itself linear, so that the
  221. # preserve-vs-flatten question is moot anyway.
  222. #
  223. # See https://stackoverflow.com/questions/38269092/is-it-possible-to-put-preserve-merges-in-the-gitconfig
  224. #
  225. # While preserving merges is probably generally superior, in at least a
  226. # few ways, to discarding them when rebasing, the fact is that rebase
  227. # cannot preserve them. The only thing it can do, once some commits
  228. # have been copied to new commits, is re-perform them. This can have new
  229. # and/or different merge conflicts, vs the last time the merge was done.
  230. # You should also pay close attention to the restrictions on merge
  231. # preservation in the git rebase documentation.
  232. #
  233. # Without getting into a lot of detail, it always seems to me that most
  234. # commit graph subsets that "should be" rebased, rarely have any
  235. # internal merges. If such a graph subset has a single final merge, you
  236. # can simply strip away that merge (with git reset) before rebasing,
  237. # and re-do that single merge manually at the end. (In fact, git rebase
  238. # normally drops merge commits entirely, so you don't have to run the git
  239. # reset itself in some cases. The one where you do have to run it is when
  240. # the merge is into the branch onto which you intend to rebase. This is
  241. # where git pull actually does the right thing when it uses
  242. # `git rebase -p`, except that it fails to check for, and warn about,
  243. # internal merges, which are sort of warning signs that rebasing might
  244. # not be a good idea.
  245. #
  246. pp = pull --rebase=preserve
  247. ### rebase ###
  248. # rebase - forward-port local commits to the updated upstream head.
  249. rb = rebase
  250. # rebase abort - cancel the rebasing process
  251. rba = rebase --abort
  252. # rebase - continue the rebasing process after resolving a conflict manually and updating the index with the resolution.
  253. rbc = rebase --continue
  254. # rebase - restart the rebasing process by skipping the current patch.
  255. rbs = rebase --skip
  256. # rbi - rebase interactive on our unpushed commits.
  257. #
  258. # Before we push our local changes, we may want to do some cleanup,
  259. # to improve our commit messages or squash related commits together.
  260. #
  261. # Let's say I've pushed two commits that are related to a new feature and
  262. # I have another where I made a spelling mistake in the commit message.
  263. # When I run "git rbi" I get dropped into my editor with this:
  264. #
  265. # pick 7f06d36 foo
  266. # pick ad544d0 goo
  267. # pick de3083a hoo
  268. #
  269. # Let's say I want to squash the "foo" and "goo" commits together,
  270. # and also change "hoo" to say "whatever". To do these, I change "pick"
  271. # to say "s" for squash; this tells git to squash the two together;
  272. # I also edit "hoo" to rename it to "whatever". I make the file look like:
  273. #
  274. # pick 7f06d36 foo
  275. # s ad544d0 goo
  276. # r de3083a whatever
  277. #
  278. # This gives me two new commit messages to edit, which I update.
  279. # Now when I push the remote repo host receives two commits
  280. #
  281. # 3400455 - foo
  282. # 5dae0a0 - whatever
  283. #
  284. rbi = rebase --interactive @{upstream}
  285. # See https://blog.filippo.io/git-fixup-amending-an-older-commit/
  286. # This is a slightly modified version
  287. fixup = "!f() { TARGET=$(git rev-parse \"$1\"); git commit --fixup=$TARGET && GIT_EDITOR=true git rebase --interactive --autosquash $TARGET~; }; f"
  288. ### reflog ###
  289. # reflog - reference log that manages when tips of branches are updated.
  290. rl = reflog
  291. ### remote ###
  292. # remote - manage set of tracked repositories [same as "r"].
  293. rr = remote
  294. # remote show - gives some information about the remote <name>.
  295. rrs = remote show
  296. # remote update - fetch updates for a named set of remotes in the repository as defined by remotes.
  297. rru = remote update
  298. # remote prune - deletes all stale remote-tracking branches under <name>.
  299. rrp = remote prune
  300. incoming = !git remote update --prune; git log ..@{upstream}
  301. outgoing = log @{upstream}..
  302. # Push to all remotes
  303. push-to-all-remotes = !git remote | xargs -I% -n1 git push %
  304. ### revert ###
  305. # revert - undo the changes from some existing commits
  306. rv = revert
  307. # revert without autocommit; useful when you're reverting more than one commits' effect to your index in a row.
  308. rvnc = revert --no-commit
  309. ### show-branch ###
  310. # show-branch - print a list of branches and their commits.
  311. sb = show-branch
  312. ### submodule ###
  313. # submodule - enables foreign repositories to be embedded within a dedicated subdirectory of the source tree.
  314. sm = submodule
  315. # submodule init
  316. smi = submodule init
  317. # submodule add
  318. sma = submodule add
  319. # submodule sync
  320. sms = submodule sync
  321. # submodule update
  322. smu = submodule update
  323. # submodule update with initialize
  324. smui = submodule update --init
  325. # submodule update with initialize and recursive; this is useful to bring a submodule fully up to date.
  326. smuir = submodule update --init --recursive
  327. ### status ###
  328. # status with short format instead of full details
  329. ss = status --short
  330. # status with short format and showing branch and tracking info.
  331. ssb = status --short --branch
  332. ### ALIAS MANAGEMENT ###
  333. # Show our defined alias list
  334. aliases = "!git config --get-regexp '^alias\\.' | cut -c 7- | sed 's/ / = /'"
  335. add-alias = "!f() { [ $# = 3 ] && git config $1 alias.\"$2\" \"$3\" && return 0 || echo \"Usage: git add-(local|global)-alias <new alias> <original command>\" >&2 && return 1; }; f"
  336. add-global-alias = "!git add-alias --global"
  337. add-local-alias = "!git add-alias --local"
  338. # Rename an alias
  339. rename-alias = "!f() { [ $# = 3 ] && [ $2 != $3 ] && [ ! -z \"$(git config $1 --get alias.$2)\" ] && [ -z \"$(git config $1 --get alias.$3)\" ] && git config $1 alias.$3 \"$(git config $1 --get alias.$2)\" && git config $1 --unset alias.$2 && return 0 || echo \"Usage: git rename-(local|global)-alias <alias existing name> <new alias name>\nThe alias you are going to rename must exist and new name must not exist.\" >&2 && return 1; };f"
  340. rename-global-alias = "!git rename-alias --global"
  341. rename-local-alias = "!git rename-alias --local"
  342. # Last tag in the current branch
  343. lasttag = describe --tags --abbrev=0
  344. # Latest annotated tag in all branches
  345. lasttagged = !git describe --tags `git rev-list --tags --max-count=1`
  346. # From https://gist.github.com/492227
  347. head = log -n1
  348. heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
  349. lost = !"git fsck | awk '/dangling commit/ {print $3}' | git show --format='SHA1: %C(yellow)%h%Creset %f' --stdin | awk '/SHA1/ {sub(\"SHA1: \", \"\"); print}'"
  350. ### diff-* ###
  351. diff-all = !"for name in $(git diff --name-only $1); do git difftool $1 $name & done"
  352. diff-changes = diff --name-status -r
  353. diff-stat = diff --stat --ignore-space-change -r
  354. diff-staged = diff --cached
  355. # Diff using our preferred options. A.k.a. `dd`.
  356. diff-deep = diff --check --dirstat --find-copies --find-renames --histogram --color
  357. ### grep-* ###
  358. # Find text in any commit ever.
  359. grep-all = !"f() { git rev-list --all | xargs git grep \"$@\"; }; f"
  360. # Find text and group the output lines. A.k.a. `gg`.
  361. grep-group = grep --break --heading --line-number --color
  362. # grep with ack-like formatting
  363. grep-ack = \
  364. -c color.grep.linenumber=\"bold yellow\" \
  365. -c color.grep.filename=\"bold green\" \
  366. -c color.grep.match=\"reverse yellow\" \
  367. grep --break --heading --line-number
  368. ### init ###
  369. # initalize a repo and immediate add an empty commit, which makes rebase easier.
  370. init-empty = !"f() { git init && git commit --allow-empty --allow-empty-message --message ''; }; f"
  371. ### merge-* ###
  372. # Given a merge commit, find the span of commits that exist(ed).
  373. # Not so useful in itself, but used by other aliases.
  374. # Thanks to Rob Miller for the merge-span-* aliaes.
  375. merge-span = !"f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f"
  376. # Find the commits that were introduced by a merge
  377. merge-span-log = "!git log `git merge-span .. $1`"
  378. # Show the changes that were introduced by a merge
  379. merge-span-diff = !"git diff `git merge-span ... $1`"
  380. # Show the changes that were introduced by a merge, in your difftool
  381. merge-span-difftool = !"git difftool `git merge-span ... $1`"
  382. # Interactively rebase all the commits on the current branch
  383. rebase-branch = !"git rebase --interactive `git merge-base master HEAD`"
  384. # Sort by date for branches; can be useful for spring cleaning
  385. refs-by-date = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)'
  386. # Find all objects that aren't referenced by any other object (orphans).
  387. # To help an orphan, we create a new branch with the orphan's commit hash,
  388. # then merge it into our current branch:
  389. #
  390. # git branch foo <commit>
  391. # git merge foo
  392. #
  393. orphans = fsck --full
  394. # List all blobs by size in bytes.
  395. # By [CodeGnome](http://www.codegnome.com/)
  396. rev-list-all-objects-by-size = !"git rev-list --all --objects | awk '{print $1}'| git cat-file --batch-check | fgrep blob | sort -k3nr"
  397. # List all objects by size in bytes and file name.
  398. # By [raphinesse](https://stackoverflow.com/users/380229/raphinesse)
  399. rev-list-all-objects-by-size-and-name = !"git rev-list --all --objects | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '/^blob/ {print substr($0,6)}' | sort --numeric-sort --key=2"
  400. ### LOG ALIASES ###
  401. # Show log of changes, most recent first
  402. log-changes = log --oneline --reverse
  403. # Show log of new commits after you fetched, with stats, excluding merges
  404. log-fresh = log ORIG_HEAD.. --stat --no-merges
  405. # Show log in our preferred format for our key performance indicators. A.k.a. `ll`.
  406. log-like = log --graph --topo-order --date=short --abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn]%Creset %Cblue%G?%Creset'
  407. # Show log in our preferred format for our key performance indicators, with long items. A.k.a. `lll`.
  408. log-like-long = log --graph --topo-order --date=iso8601-strict --no-abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn <%ce>]%Creset %Cblue%G?%Creset'
  409. # Show log with dates in our local timezone
  410. log-local = log --date=local
  411. # Show the log for my own commits by my own user email
  412. log-my = !git log --author $(git config user.email)
  413. # Show log as a graph
  414. log-graph = log --graph --all --oneline --decorate
  415. # Show the date of the earliest commit, in strict ISO 8601 format
  416. log-first-date = !"git log --date-order --format=%cI | tail -1"
  417. # Show the date of the latest commit, in strict ISO 8601 format
  418. log-latest-date = log -1 --date-order --format=%cI
  419. # Show the log of the recent hour, day, week, month, year
  420. log-hour = log --since=1-hour-ago
  421. log-day = log --since=1-day-ago
  422. log-week = log --since=1-week-ago
  423. log-month = log --since=1-month-ago
  424. log-year = log --since=1-year-ago
  425. # Show the log of my own recent hour, day, week, month, year
  426. log-my-hour = log --author $(git config user.email) --since=1-hour-ago
  427. log-my-day = log --author $(git config user.email) --since=1-day-ago
  428. log-my-week = log --author $(git config user.email) --since=1-week-ago
  429. log-my-month = log --author $(git config user.email) --since=1-month-ago
  430. log-my-year = log --author $(git config user.email) --since=1-year-ago
  431. # Show a specific format string and its number of log entries
  432. log-of-format-and-count = "!f() { format=\"$1\"; shift; git log $@ --format=oneline --format="$format" | awk '{a[$0]++}END{for(i in a){print i, a[i], int((a[i]/NR)*100) \"%\"}}' | sort; }; f"
  433. log-of-count-and-format = "!f() { format=\"$1\"; shift; git log $@ --format=oneline --format="$format" | awk '{a[$0]++}END{for(i in a){print a[i], int((a[i]/NR)*100) \"%\", i}}' | sort -nr; }; f"
  434. # Show the number of log entries by a specific format string and date format string
  435. log-of-format-and-count-with-date = "!f() { format=\"$1\"; shift; date_format=\"$1\"; shift; git log $@ --format=oneline --format=\"$format\" --date=format:\"$date_format\" | awk '{a[$0]++}END{for(i in a){print i, a[i], int((a[i]/NR)*100) \"%\"}}' | sort -r; }; f"
  436. log-of-count-and-format-with-date = "!f() { format=\"$1\"; shift; date_format=\"$1\"; shift; git log $@ --format=oneline --format=\"$format\" --date=format:\"$date_format\" | awk '{a[$0]++}END{for(i in a){print a[i], int((a[i]/NR)*100) \"%\", i}}' | sort -nr; }; f"
  437. # Show the number of log items by email
  438. log-of-email-and-count = "!f() { git log-of-format-and-count \"%aE\" $@; }; f"
  439. log-of-count-and-email = "!f() { git log-of-count-and-format \"%aE\" $@; }; f"
  440. # Show the number of log items by hour
  441. log-of-hour-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m-%dT%H\" $@ ; }; f"
  442. log-of-count-and-hour = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m-%dT%H\" $@ ; }; f"
  443. # Show the number of log items by day
  444. log-of-day-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m-%d\" $@ ; }; f"
  445. log-of-count-and-day = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m-%d\" $@ ; }; f"
  446. # Show the number of log items by week
  447. log-of-week-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y#%V\" $@; }; f"
  448. log-of-count-and-week = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y#%V\" $@; }; f"
  449. # Show the number of log items by month
  450. log-of-month-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m\" $@ ; }; f"
  451. log-of-count-and-month = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m\" $@ ; }; f"
  452. # Show the number of log items by year
  453. log-of-year-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y\" $@ ; }; f"
  454. log-of-count-and-year = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y\" $@ ; }; f"
  455. # Show the number of log items by hour of day
  456. log-of-hour-of-day-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%H\" $@; }; f"
  457. log-of-count-and-hour-of-day = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%H\" $@; }; f"
  458. # Show the number of log items by day of week
  459. log-of-day-of-week-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%u\" $@; }; f"
  460. log-of-count-and-day-of-week = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%u\" $@; }; f"
  461. # Show the number of log items by week of year
  462. log-of-week-of-year-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%V\" $@; }; f"
  463. log-of-count-and-week-of-year = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%V\" $@; }; f"
  464. # TODO
  465. log-refs = log --all --graph --decorate --oneline --simplify-by-decoration --no-merges
  466. log-timeline = log --format='%h %an %ar - %s'
  467. log-local = log --oneline origin..HEAD
  468. log-fetched = log --oneline HEAD..origin/master
  469. # chart: show a summary chart of activity per author.
  470. #
  471. # Example:
  472. #
  473. # $ git chart
  474. # ..X..........X...2..12 alice@example.com
  475. # ....2..2..13.......... bob@example.com
  476. # 2.....1....11......... carol@example.com
  477. # ..1............1..1... david@example.com
  478. # ....1.......1.3.3.22.2 eve@example.com
  479. #
  480. # The chart rows are the authors.
  481. # TODO: sort the rows meaningfully,
  482. # such as alphabetically, or by count.
  483. #
  484. # The chart columns are the days.
  485. # The chart column prints one character per day.
  486. #
  487. # * For 1-9 commits, show the number.
  488. # * For 10 or more commits, show "X" as a visual indicator.
  489. # * For no commits, show "." as a visual placeholder.
  490. #
  491. # The chart timeline adjusts the date range automatically:
  492. #
  493. # * The timeline starts with the date of the earliest commit.
  494. # * The timeline stops with the date of the latest commit.
  495. # * The intent is to show the most relevant information.
  496. #
  497. # The chart default is to look at the past 6 weeks;
  498. # this gives a good balance of recency and speed
  499. # for a team that's currently working on a repo,
  500. # and also gives a good balance of fitting within
  501. # one terminal window 80 character width.
  502. #
  503. # You can adjust how far back the chart looks,
  504. # by providing your own `--since` parameter.
  505. # For example if you want to chart an older repo,
  506. # that does not have any recent commits, then you
  507. # you must provide a longer `--since` parameter.
  508. #
  509. chart = "!f() { \
  510. git log \
  511. --format=oneline \
  512. --format=\"%aE %at\" \
  513. --since=6-weeks-ago \
  514. $* | \
  515. awk ' \
  516. function time_to_slot(t) { return strftime(\"%Y-%m-%d\", t, true) } \
  517. function count_to_char(i) { return (i > 0) ? ((i < 10) ? i : \"X\") : \".\" } \
  518. BEGIN { \
  519. time_min = systime(); time_max = 0; \
  520. SECONDS_PER_DAY=86400; \
  521. } \
  522. { \
  523. item = $1; \
  524. time = 0 + $2; \
  525. if (time > time_max){ time_max = time } else if (time < time_min){ time_min = time }; \
  526. slot = time_to_slot(time); \
  527. items[item]++; \
  528. slots[slot]++; \
  529. views[item, slot]++; \
  530. } \
  531. END{ \
  532. printf(\"Chart time range %s to %s.\\n\", time_to_slot(time_min), time_to_slot(time_max)); \
  533. time_max_add = time_max += SECONDS_PER_DAY; \
  534. for(item in items){ \
  535. row = \"\"; \
  536. for(time = time_min; time < time_max_add; time += SECONDS_PER_DAY) { \
  537. slot = time_to_slot(time); \
  538. count = views[item, slot]; \
  539. row = row count_to_char(count); \
  540. } \
  541. print row, item; \
  542. } \
  543. }'; \
  544. }; f"
  545. # churn: show log of files that have many changes
  546. #
  547. # * Written by (Corey Haines)[http://coreyhaines.com/]
  548. # * Scriptified by Gary Bernhardt
  549. # * Obtained from https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn
  550. # * Edited for GitAlias.com repo by Joel Parker Henderson
  551. # * Comments by Mislav http://mislav.uniqpath.com/2014/02/hidden-documentation/
  552. #
  553. # Show churn for whole repo:
  554. #
  555. # $ git churn
  556. #
  557. # Show churn for specific directories:
  558. #
  559. # $ git churn app lib
  560. #
  561. # Show churn for a time range:
  562. #
  563. # $ git churn --since=1-month-ago
  564. #
  565. # These are all standard arguments to `git log`.
  566. #
  567. # It's possible to get valuable insight from history of a project not only
  568. # by viewing individual commits, but by analyzing sets of changes as a whole.
  569. # For instance, `git churn` compiles stats about which files change the most.
  570. #
  571. # For example, to see where work on an app was focused on in the past month:
  572. #
  573. # $ git churn --since=1-month-ago app/ | tail
  574. #
  575. # This can also highlight potential problems with technical debt in a project.
  576. # A specific file changing too often is generally a red flag, since it probably
  577. # means the file either needed to be frequently fixed for bugs, or the file
  578. # holds too much responsibility and should be split into smaller units.
  579. #
  580. # Similar methods of history analysis can be employed to see which people were
  581. # responsible recently for development of a certain part of the codebase.
  582. #
  583. # For instance, to see who contributed most to the API part of an application:
  584. #
  585. # $ git log --format='%an' --since=1-month-ago app/controllers/api/ | \
  586. # sort | uniq -c | sort -rn | head
  587. #
  588. # 109 Alice Anderson
  589. # 13 Bob Brown
  590. # 7 Carol Clark
  591. #
  592. churn = !"f() { git log --all --find-copies --find-renames --name-only --format='format:' \"$@\" | awk 'NF{a[$0]++}END{for(i in a){print a[i], i}}' | sort -rn;};f"
  593. # summary: print a helpful summary of some typical metrics
  594. summary = "!f() { \
  595. printf \"Summary of this branch...\n\"; \
  596. printf \"%s\n\" $(git rev-parse --abbrev-ref HEAD); \
  597. printf \"%s first commit timestamp\n\" $(git log --date-order --format=%cI | tail -1); \
  598. printf \"%s latest commit timestamp\n\" $(git log -1 --date-order --format=%cI); \
  599. printf \"%d commit count\n\" $(git rev-list --count HEAD); \
  600. printf \"%d date count\n\" $(git log --format=oneline --format=\"%ad\" --date=format:\"%Y-%m-%d\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
  601. printf \"%d tag count\n\" $(git tag | wc -l); \
  602. printf \"%d author count\n\" $(git log --format=oneline --format=\"%aE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
  603. printf \"%d committer count\n\" $(git log --format=oneline --format=\"%cE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
  604. printf \"%d local branch count\n\" $(git branch | grep -v \" -> \" | wc -l); \
  605. printf \"%d remote branch count\n\" $(git branch -r | grep -v \" -> \" | wc -l); \
  606. printf \"\nSummary of this directory...\n\"; \
  607. printf \"%s\n\" $(pwd); \
  608. printf \"%d file count via git ls-files\n\" $(git ls-files | wc -l); \
  609. printf \"%d file count via find command\n\" $(find . | wc -l); \
  610. printf \"%d disk usage\n\" $(du -s | awk '{print $1}'); \
  611. printf \"\nMost-active authors, with commit count and %%...\n\"; git log-of-count-and-email | head -7; \
  612. printf \"\nMost-active dates, with commit count and %%...\n\"; git log-of-count-and-day | head -7; \
  613. printf \"\nMost-active files, with churn count\n\"; git churn | head -7; \
  614. }; f"
  615. ### REF ALIASES ###
  616. ref-recent = "!git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) %(objectname:short) %(contents:subject)' refs/heads/"
  617. ### LOOKUP ALIASES ###
  618. # whois: given a string for an author, try to figure out full name and email:
  619. whois = "!sh -c 'git log --regexp-ignore-case -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -"
  620. # Given any git object, try to show it briefly
  621. whatis = show --no-patch --pretty='tformat:%h (%s, %ad)' --date=short
  622. # Show who contributed with summarized changes
  623. who = shortlog --summary --
  624. # Show who contributed, in descending order by number of commits
  625. whorank = shortlog --summary --numbered --no-merges
  626. # List all issues mentioned in commit messages between range of commits
  627. #
  628. # Replace `\\\"ISSUE-[0-9]\\+\\\"` regular expression with one matching your issue tracking system.
  629. # For Jira it should be as simple as putting your project name in place of `ISSUE`.
  630. #
  631. # Best used with tags:
  632. # $ git issues v1.0..v1.1
  633. #
  634. # But will work with any valid commit range:
  635. # $ git issues master..HEAD
  636. issues = !sh -c \"git log $1 --oneline | grep -o \\\"ISSUE-[0-9]\\+\\\" | sort -u\"
  637. # Show the commit's parents
  638. commit-parents = !"f(){ git cat-file -p \"${*:-HEAD}\" | sed -n '/0/,/^ *$/{/^parent /p}'; };f"
  639. # Is the commit a merge commit? If yes exit 0, else exit 1
  640. commit-is-merge = !"f(){ [ -n \"$(git commit-parents \"$*\" | sed '0,/^parent /d')\" ];};f"
  641. # Show the commit's keyword-marked lines.
  642. #
  643. # Show each line in the commit message that starts with zero or more blanks,
  644. # then a keyword (alphanum and dash characters), then a colon.
  645. #
  646. # Example commit:
  647. #
  648. # commit ce505d161fccdbc8d4bf12047846de7433ad6d04
  649. # Author: Joel Parker Henderson <joel@joelparkerhenderson.com>
  650. # Date: Tue May 28 11:53:47 2019 -0700
  651. #
  652. # Add feature foo
  653. #
  654. # This commit is to add feature foo.
  655. #
  656. # Time: 5 hours
  657. # Cost: 600 USD
  658. #
  659. # Command:
  660. #
  661. # $ git commit-message-key-lines ce505d161fccdbc8d4bf12047846de7433ad6d04
  662. # Commit: ce505d161fccdbc8d4bf12047846de7433ad6d04
  663. # Author: Joel Parker Henderson <joel@joelparkerhenderson.com>
  664. # Date: Tue May 28 11:53:47 2019 -0700
  665. # Time: 5 hours
  666. # Cost: 600 USD
  667. #
  668. # Normalize the output:
  669. #
  670. # * Start the output with "Commit: <commit>"
  671. #
  672. # * Omit leading blanks
  673. #
  674. # * After the colon, use one space (not tab, not multiple spaces, etc.)
  675. #
  676. # Known issues:
  677. #
  678. # * TODO: improve the keyword matcher so it requires the keyword to end
  679. # in an alphanum (not a dash), and also so the dash is a separator i.e.
  680. # the matcher does not accept a dash followed by another dash.
  681. #
  682. commit-message-key-lines = "!f(){ echo \"Commit: $1\"; git log \"$1\" --format=fuller | grep \"^[[:blank:]]*[[:alnum:]][-[:alnum:]]*:\" | sed \"s/^[[:blank:]]*//; s/:[[:blank:]]*/: /\"; }; f"
  683. ### WORKFLOW ALIASES ###
  684. # Clone a git repository including all submodules
  685. cloner = clone --recursive
  686. # Clone as lean as possible, for example to checkout just one subdiretory.
  687. #
  688. # This skips fetching unneeded objects from the server.
  689. #
  690. # Command breakdown:
  691. #
  692. # * --depth 1 does a shallow clone and implies --single-branches
  693. #
  694. # * --filter=blob:none skips all blobs, but fetches all tree objects
  695. #
  696. # * --filter=tree:0 skips unneeded trees
  697. #
  698. # * --filter=combine:FILTER1+FILTER2 is the syntax to use multiple
  699. # filters at once; trying to pass --filter multiple times fails
  700. # with: "multiple filter-specs cannot be combined".
  701. #
  702. # This uses --filter=tree:0 added in Git 2.20 and --filter=combine
  703. # composite filter added in Git 2.24.
  704. #
  705. # The server should be configured with:
  706. #
  707. # git config --local uploadpack.allowfilter 1
  708. # git config --local uploadpack.allowanysha1inwant 1
  709. #
  710. # An extension was made to the Git remote protocol to support this
  711. # feature in v2.19.0 and actually skip fetching unneeded objects.
  712. # There was server support then, but it can be locally tested.
  713. #
  714. # Credit: https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
  715. #
  716. clone-lean = clone --depth 1 --filter=combine:blob:none+tree:0 --no-checkout
  717. # Stash aliases for push & pop
  718. #
  719. # Note that if you are using an older version of git, before 2.16.0,
  720. # then you can use the older "stash save" instead of the newer "stash push".
  721. save = stash push
  722. pop = stash pop
  723. # Stash snapshot - from http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
  724. # Take a snapshot of your current working tree without removing changes.
  725. # This is handy for refactoring where you can't quite fit what you've done
  726. # into a commit but daren't stray too far from now without a backup.
  727. #
  728. # Running this:
  729. #
  730. # $ git snapshot
  731. #
  732. # Creates this stash:
  733. #
  734. # stash@{0}: On feature/handy-git-tricks: snapshot: Mon Apr 8 12:39:06 BST 2013
  735. #
  736. # And seemingly no changes to your working tree.
  737. #
  738. snapshot = !git stash push "snapshot: $(date)" && git stash apply "stash@{0}"
  739. # When you're a little worried that the world is coming to an end
  740. panic = !tar cvf ../panic.tar *
  741. # Create an archive file of everything in the repo
  742. archive = !"f() { top=$(rev-parse --show-toplevel); cd $top; tar cvf $top.tar $top ; }; f"
  743. # Do everything we can to synchronize all changes for the current branch.
  744. #
  745. # * git get: fetch and prune, pull and rebase, then update submodules
  746. # * git put: commit all items, then push
  747. #
  748. # If you want to preserve merges, then we recommend you set this:
  749. #
  750. # git config pull.rebase preserve
  751. #
  752. # TODO: handle tags, delete superfluous branches, and add error handing.
  753. #
  754. get = !git fetch --prune && git pull --rebase && git submodule update --init --recursive
  755. put = !git commit --all && git push
  756. # Do everything we can to make the local repo like the master branch.
  757. #
  758. # TODO: handle tags, and delete superfluous branches, and add error handling.
  759. #
  760. mastery = !git checkout master && git fetch origin --prune && git reset --hard origin/master
  761. # Ignore all untracked files by appending them to .gitignore:
  762. ignore = "!git status | grep -P \"^\\t\" | grep -vF .gitignore | sed \"s/^\\t//\" >> .gitignore"
  763. # Do a push/pull for just one branch
  764. push1 = "!git push origin $(git branch-name)"
  765. pull1 = "!git pull origin $(git branch-name)"
  766. # Track and untrack, with default parameters, and with printing the command
  767. track = "!f(){ branch=$(git rev-parse --abbrev-ref HEAD); cmd=\"git branch $branch -u ${1:-origin}/${2:-$branch}\"; echo $cmd; $cmd; }; f"
  768. untrack = "!f(){ branch=$(git rev-parse --abbrev-ref HEAD); cmd=\"git branch --unset-upstream ${1:-$branch}\"; echo $cmd; $cmd; }; f"
  769. # Track all remote branches that aren't already being tracked;
  770. # this is a bit hacky because of the parsing, and we welcome
  771. # better code that works using more-specific git commands.
  772. track-all-remote-branches = !"f() { git branch -r | grep -v ' -> ' | sed 's/^ \\+origin\\///' ; }; f"
  773. ##
  774. # Reset & Undo
  775. ##
  776. # Reset and undo aliases are ways to move backwards on the commit chain.
  777. # We find that novices prefer the wording "undo"; experts prefer "reset".
  778. reset-commit = reset --soft HEAD~1
  779. reset-commit-hard = reset --hard HEAD~1
  780. reset-commit-clean = !git reset --hard HEAD~1 && git clean -fd
  781. reset-to-pristine = !git reset --hard && git clean -ffdx
  782. reset-to-upstream = !git reset --hard $(git upstream-name)
  783. # Undo is simply a synonym for "reset" because "undo" can help novices.
  784. undo-commit = reset --soft HEAD~1
  785. undo-commit-hard = reset --hard HEAD~1
  786. undo-commit-clean = !git reset --hard HEAD~1 && git clean -fd
  787. undo-to-pristine = !git reset --hard && git clean -ffdx
  788. undo-to-upstream = !git reset --hard $(git upstream-name)
  789. # Nicknames
  790. uncommit = reset --soft HEAD~1
  791. unadd = reset HEAD
  792. unstage = reset HEAD
  793. # Discard changes in a (list of) file(s) in working tree
  794. discard = checkout --
  795. # Clean and discard changes and untracked files in working tree
  796. cleanout = !git clean -df && git checkout -- .
  797. # Expunge a file everywhere; this command is typically for a serious problem,
  798. # such as accidentally committing a file of sensitive data, such as passwords.
  799. # After you use command, you will likely need to force push everything.
  800. # See https://help.github.com/articles/removing-sensitive-data-from-a-repository/
  801. expunge = !"f() { git filter-branch --force --index-filter \"git rm --cached --ignore-unmatch $1\" --prune-empty --tag-name-filter cat -- --all }; f"
  802. # Edit all files of the given type
  803. edit-cached = !"f() { git ls-files --cached | sort -u ; }; `git var GIT_EDITOR` `f`"
  804. edit-deleted = !"f() { git ls-files --deleted | sort -u ; }; `git var GIT_EDITOR` `f`"
  805. edit-others = !"f() { git ls-files --others | sort -u ; }; `git var GIT_EDITOR` `f`"
  806. edit-ignored = !"f() { git ls-files --ignored | sort -u ; }; `git var GIT_EDITOR` `f`"
  807. edit-killed = !"f() { git ls-files --killed | sort -u ; }; `git var GIT_EDITOR` `f`"
  808. edit-modified = !"f() { git ls-files --modified | sort -u ; }; `git var GIT_EDITOR` `f`"
  809. edit-stage = !"f() { git ls-files --stage | cut -f2 | sort -u ; }; `git var GIT_EDITOR` `f`"
  810. # Editing and adding conflicted files: when we get many merge conflicts
  811. # and want to quickly solve them using an editor, then add the files.
  812. edit-unmerged = !"f() { git ls-files --unmerged | cut -f2 | sort -u ; }; `git var GIT_EDITOR` `f`"
  813. add-unmerged = !"f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"
  814. # Ours & Theirs - easy merging when you know which files you want
  815. #
  816. # Sometimes during a merge you want to take a file from one side wholesale.
  817. #
  818. # The following aliases expose the ours and theirs commands which let you
  819. # pick a file(s) from the current branch or the merged branch respectively.
  820. #
  821. # * ours: checkout our version of a file and add it
  822. # * theirs: checkout their version of a file and add it
  823. #
  824. # N.b. the function is there as hack to get $@ doing
  825. # what you would expect it to as a shell user.
  826. #
  827. ours = !"f() { git checkout --ours $@ && git add $@; }; f"
  828. theirs = !"f() { git checkout --theirs $@ && git add $@; }; f"
  829. # Work In Progress: from https://gist.github.com/492227 and VonC on stackoverflow.
  830. # This enables a quick way to add all new and modified files to the index,
  831. # while cleaning the index from the files removed from the working tree;
  832. # this cleaning will facilitate a rebase, because there won't be any conflict
  833. # due to an "unclean" working directory (not in sync with the index).
  834. # The unwip will restore the deleted files to the working tree.
  835. wip = !"git add --all; git ls-files --deleted -z | xargs -0 git rm; git commit --message=wip"
  836. unwip = !"git log -n 1 | grep -q -c wip && git reset HEAD~1"
  837. # Assume
  838. #
  839. # Sometimes we want to change a file in a repo, but never check in your edits.
  840. # We can't use .gitignore because the file is tracked. We use update-index.
  841. #
  842. # If you interact with big corporate projects, such as projects in Subversion,
  843. # then you might run into the need to ignore certain files which are under
  844. # Subversion control, yet you need to modify them but not commit.
  845. # The assume-unchanged flag comes to the rescue.
  846. #
  847. # Suppose we want to edit passwords.txt and for god's sake never check it in:
  848. #
  849. # $ git status
  850. # modified passwords.txt
  851. # modified foo.txt
  852. #
  853. # $ git assume passwords.txt
  854. # $ git status
  855. # modified foo.txt
  856. #
  857. # $ git assumed
  858. # passwords.txt
  859. #
  860. # $ git unassume passwords.txt
  861. # $ git status
  862. # modified passwords.txt
  863. # modified foo.txt
  864. #
  865. # Thanks to http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
  866. # Thanks to http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
  867. assume = update-index --assume-unchanged
  868. unassume = update-index --no-assume-unchanged
  869. assume-all = "!git st -s | awk {'print $2'} | xargs git assume"
  870. unassume-all = "!git assumed | xargs git update-index --no-assume-unchanged"
  871. assumed = !"git ls-files -v | grep ^h | cut -c 3-"
  872. # Delete all branches that have already been merged into the master branch.
  873. master-cleanse = !git master-cleanse-local; git master-cleanse-remote
  874. # Delete all local branches that have been merged into the local master branch.
  875. master-cleanse-local = "!git checkout master && git branch --merged | xargs git branch --delete"
  876. # Delete all remote branches that have been merged into the remote master branch.
  877. master-cleanse-remote = !"git branch --remotes --merged origin/master | sed 's# *origin/##' | grep -v '^master$' xargs -I% git push origin :% 2>&1 | grep --colour=never 'deleted'"
  878. # Publish the current branch by pushing it to the remote "origin",
  879. # and setting the current branch to track the upstream branch.
  880. publish = !"git push --set-upstream origin $(git branch-name)"
  881. # Unpublish the current branch by deleting the
  882. # remote version of the current branch.
  883. unpublish = !"git push origin :$(git branch-name)"
  884. # Delete a branch name, then create the same branch name based on master -
  885. # useful if you have, for example, a development branch and master branch
  886. # and they go out of sync, and you want to nuke the development branch.
  887. #
  888. # Calls the `publish` and `unpublish` aliases.
  889. #
  890. reincarnate = !"f() { [[ -n $@ ]] && git checkout \"$@\" && git unpublish && git checkout master && git branch -D \"$@\" && git checkout -b \"$@\" && git publish; }; f"
  891. # Friendly wording is easier to remember.
  892. # Thanks to http://gggritso.com/human-git-aliases
  893. branches = branch -a
  894. tags = tag -n1 --list
  895. stashes = stash list
  896. ### SHELL SCRIPTING ALIASES ###
  897. # Get the top level directory name
  898. top-name = rev-parse --show-toplevel
  899. # Get the current branch name
  900. branch-name = rev-parse --abbrev-ref HEAD
  901. # Get the upstream branch name
  902. upstream-name = !git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
  903. # Execute shell scripts. Git always runs scripts in the top directory.
  904. # For example "git exec pwd" will always show you the top directory.
  905. exec = ! exec
  906. ### MAINTENANCE ALIASES ###
  907. # pruner: prune everything that is unreachable now.
  908. #
  909. # This command takes a long time to run, perhaps even overnight.
  910. #
  911. # This is useful for removing unreachable objects from all places.
  912. #
  913. # By [CodeGnome](http://www.codegnome.com/)
  914. #
  915. pruner = !"git prune --expire=now; git reflog expire --expire-unreachable=now --rewrite --all"
  916. # repacker: repack a repo the way Linus recommends.
  917. #
  918. # This command takes a long time to run, perhaps even overnight.
  919. #
  920. # It does the equivalent of "git gc --aggressive"
  921. # but done *properly*, which is to do something like:
  922. #
  923. # git repack -a -d --depth=250 --window=250
  924. #
  925. # The depth setting is about how deep the delta chains can be;
  926. # make them longer for old history - it's worth the space overhead.
  927. #
  928. # The window setting is about how big an object window we want
  929. # each delta candidate to scan.
  930. #
  931. # And here, you might well want to add the "-f" flag (which is
  932. # the "drop all old deltas", since you now are actually trying
  933. # to make sure that this one actually finds good candidates.
  934. #
  935. # And then it's going to take forever and a day (ie a "do it overnight"
  936. # thing). But the end result is that everybody downstream from that
  937. # repository will get much better packs, without having to spend any effort
  938. # on it themselves.
  939. #
  940. # http://metalinguist.wordpress.com/2007/12/06/the-woes-of-git-gc-aggressive-and-how-git-deltas-work/
  941. #
  942. # We also add the --window-memory limit of 1 gig, which helps protect
  943. # us from a window that has very large objects such as binary blobs.
  944. #
  945. repacker = repack -a -d -f --depth=300 --window=300 --window-memory=1g
  946. # Do everything we can to optimize the repository.
  947. #
  948. # This command takes a long time to run, perhaps even overnight.
  949. #
  950. # Currently, this command simply calls `git pruner` and `git repacker`.
  951. # There's a step that may be unnecessarying, calling `git prune-pack`.
  952. #
  953. optimize = !git pruner; git repacker; git prune-packed
  954. ### ADVANCED ALIASES ###
  955. # Search for a given string in all patches and print commit messages.
  956. # Posted by Mikko Rantalainen on StackOverflow.
  957. #
  958. # Example: search for any commit that adds or removes string "foobar"
  959. # git searchcommits foobar
  960. #
  961. # Example: search commits for string "foobar" in directory src/lib
  962. # git searchcommits foobar src/lib
  963. #
  964. # Example: search commits for "foobar", print full diff of commit with 1 line context
  965. # git searchcommits foobar --pickaxe-all -U1 src/lib
  966. searchcommits = !"f() { query=\"$1\"; shift; git log -S\"$query\" \"$@\"; }; f \"$@\""
  967. # A 'debug' alias to help debugging builtins: when debugging builtins,
  968. # we use gdb to analyze the runtime state. However, we have to disable
  969. # the pager, and often we have to call the program with arguments.
  970. # If the program to debug is a builtin, we use this alias.
  971. debug = !GIT_PAGER= gdb --args git
  972. # Getting the diff of only one function: when we want to see just the
  973. # differences of one function in one file in two different commits,
  974. # we create two temp files which contain only the function, then diff.
  975. # Use this alias this way: git funcdiff <old-rev> <new-rev> <path> <function>
  976. # diff-func = !sh -c "git show \"\$1:\$3\" | sed -n \"/^[^ \t].*\$4(/,/^}/p\" > .tmp1 && git show \"\$2:\$3\" | sed -n \"/^[^ \t].*\$4(/,/^}/p\" > .tmp2 && git diff --no-index .tmp1 .tmp2" -
  977. # Calling "interdiff" between commits: if upstream applied a
  978. # slightly modified patch, and we want to see the modifications,
  979. # we use the program interdiff of the patchutils package.
  980. intercommit = !sh -c 'git show "$1" > .git/commit1 && git show "$2" > .git/commit2 && interdiff .git/commit[12] | less -FRS' -
  981. # Prune all your stale remote branches: there's no way to tell
  982. # git remote update to prune stale branches, and git remote prune
  983. # does not understand --all. So here is a shell command to do it.
  984. prune-all = !git remote | xargs -n 1 git remote prune
  985. # Thanks to cody cutrer
  986. cherry-pick-merge = !"sh -c 'git cherry-pick --no-commit --mainline 1 $0 && \
  987. git log -1 --pretty=%P $0 | cut -b 42- > .git/MERGE_HEAD && \
  988. git commit --verbose'"
  989. # Thanks to jtolds on stackoverflow
  990. remote-ref = !"sh -c ' \
  991. local_ref=$(git symbolic-ref HEAD); \
  992. local_name=${local_ref##refs/heads/}; \
  993. remote=$(git config branch.\"#local_name\".remote || echo origin); \
  994. remote_ref=$(git config branch.\"$local_name\".merge); \
  995. remote_name=${remote_ref##refs/heads/}; \
  996. echo remotes/$remote/$remote_name'"
  997. # Thanks to jtolds on stackoverflow
  998. rebase-recent = !git rebase --interactive $(git remote-ref)
  999. # Use graphviz for display.
  1000. # This produces output that can be displayed using dotty, for example:
  1001. # $ git graphviz HEAD~100..HEAD~60 | dotty /dev/stdin
  1002. # $ git graphviz --first-parent master | dotty /dev/stdin
  1003. graphviz = !"f() { echo 'digraph git {' ; git log --pretty='format: %h -> { %p }' \"$@\" | sed 's/[0-9a-f][0-9a-f]*/\"&\"/g' ; echo '}'; }; f"
  1004. # Serve the local directory by starting a git server daemon, so others can pull/push from my machine
  1005. serve = "-c daemon.receivepack=true daemon --base-path=. --export-all --reuseaddr --verbose"
  1006. ##########################################################################
  1007. ##
  1008. # Git alias settings suitable for topic branches.
  1009. #
  1010. # These aliases are simple starting points for a simple topic flow.
  1011. # Lots of people have lots of ideas about how to do various git flows.
  1012. #
  1013. # Some people like to use a topic branch for a new feature, or a
  1014. # hotfix patch, or refactoring work, or some spike research, etc.
  1015. #
  1016. # Start work on a new topic branch, which creates your branch:
  1017. #
  1018. # $ git topic-start add-feature-foo
  1019. #
  1020. # Do some work then synchronize your changes, which integrates your branch:
  1021. #
  1022. # $ git topic-sync
  1023. #
  1024. # Stop work on a topic branch, which deletes your branch:
  1025. #
  1026. # $ git topic-stop
  1027. #
  1028. # If you want to move your branch a.k.a. rename it:
  1029. #
  1030. # $ git topic-rename
  1031. #
  1032. # Ideas for your own alias customizations:
  1033. #
  1034. # * Notify your team, such as by sending an email, posting to chat, etc.
  1035. #
  1036. # * Trigger testing of the new topic branch to ensure all tests succeed.
  1037. #
  1038. # * Update your project management software with the new topic name.
  1039. #
  1040. # Customize these aliases as you like for your own workflow.
  1041. ##
  1042. ##
  1043. # Provide the name of the topic base branch, such as "master".
  1044. #
  1045. # When we create a new topic branch, we base it on the topic base branch.
  1046. # Many projects use the default "master" branch; some projects use custom
  1047. # branches, such as "trunk", "develop", "integrate", "release", "green", etc.
  1048. #
  1049. # Customize this alias as you like for your own workflow.
  1050. ##
  1051. topic-base-branch-name = "!f(){ \
  1052. printf \"master\n\"; \
  1053. };f"
  1054. ##
  1055. # Start a topic branch.
  1056. #
  1057. # Example:
  1058. #
  1059. # git topic-start add-feature-foo
  1060. #
  1061. # We use this alias to begin work on a new feature,
  1062. # new task, new fix, new refactor, new optimization, etc.
  1063. #
  1064. # Customize this alias as you like for your own workflow.
  1065. #
  1066. # Our workflow does these steps:
  1067. #
  1068. # 1. Update the base branch.
  1069. # 2. Create a new branch with your topic name, based on the base branch.
  1070. # 3. Push the topic branch, so our team members can see the new branch.
  1071. #
  1072. # If you use a sharing site such a GitHub, and use typical settings,
  1073. # then this implementation makes your branch visible to collaborators.
  1074. #
  1075. # Many teams share branches before they are fully ready, to help
  1076. # the team provide feedback on the work-in-progress, and also to
  1077. # run any automatic tests to verify the branch runs successfully.
  1078. ##
  1079. topic-start = "!f(){ \
  1080. topic_branch=\"$1\"; \
  1081. base_branch=$(git topic-base-branch-name); \
  1082. git checkout \"$base_branch\"; git pull; \
  1083. git checkout -b \"$topic_branch\" \"$base_branch\"; \
  1084. git push --set-upstream origin \"$topic_branch\"; \
  1085. };f"
  1086. ##
  1087. # Stop a topic branch; this must be the current branch.
  1088. #
  1089. # Example:
  1090. #
  1091. # git topic-stop
  1092. #
  1093. # We use this alias to complete work on a new feature,
  1094. # new task, new fix, new refactor, new optimization, etc.
  1095. #
  1096. # Customize this alias as you like for your own workflow.
  1097. #
  1098. # Our workflow does these steps:
  1099. #
  1100. # 1. Push the topic branch.
  1101. # 2. Delete the topic branch locally.
  1102. # 3. Delete the topic branch remotely.
  1103. #
  1104. # If you use a sharing site such a GitHub, and use typical settings,
  1105. # then this implementation deletes your branch for the site.
  1106. #
  1107. # Many teams choose to delete topic branches when they are finished,
  1108. # to keep the repositories clean and with a smaller number of branches.
  1109. #
  1110. # If git says "unable to push to unqualified destination" then it means
  1111. # that the remote branch doesn't exist, so git is unable to delete it.
  1112. # That's fine; it means someone else has already deleted the branch.
  1113. # To synchronize your branch list, use "git fetch --prune".
  1114. ##
  1115. topic-stop = "!f(){ \
  1116. topic_branch=$(git branch-name); \
  1117. base_branch=$(git topic-base-branch-name); \
  1118. if [ \"$topic_branch\" = \"$base_branch\" ]; then \
  1119. printf \"You are asking to do git topic-stop,\n\"; \
  1120. printf \"but you are not currently on a topic branch;\n\"; \
  1121. printf \"you are on the base branch: $base_branch.\n\"; \
  1122. printf \"Please checkout the topic branch that you want,\n\"; \
  1123. printf \"then retry the git topic delete command.\n\"; \
  1124. else \
  1125. git push; \
  1126. git checkout \"$base_branch\"; \
  1127. git branch --delete \"$topic_branch\"; \
  1128. git push origin \":$topic_branch\"; \
  1129. fi; \
  1130. };f"
  1131. ##
  1132. # Update the current topic branch by synchronizing changes.
  1133. #
  1134. # Example:
  1135. #
  1136. # git topic-sync
  1137. #
  1138. # This implementation does these:
  1139. #
  1140. # 1. Pull any changes.
  1141. # 2. Push any changes.
  1142. #
  1143. # If you use any kind of testing framework, or test driven development,
  1144. # then it can be wise to test your topic immediately after running this,
  1145. # to ensure that any available updates are successfully integrated.
  1146. #
  1147. # Customize this alias as you like for your own workflow.
  1148. ##
  1149. topic-sync = "!f(){ \
  1150. topic_branch=$(git branch-name); \
  1151. base_branch=$(git topic-base-branch-name); \
  1152. if [ \"$topic_branch\" = \"$base_branch\" ]; then \
  1153. printf \"You are asking to do git topic-sync,\n\"; \
  1154. printf \"but you are not currently on a topic branch;\n\"; \
  1155. printf \"you are on the base branch: $base_branch.\n\"; \
  1156. printf \"Please checkout the topic branch that you want,\n\"; \
  1157. printf \"then retry the git topic delete command.\n\"; \
  1158. else \
  1159. git pull; \
  1160. git push; \
  1161. fi; \
  1162. };f"
  1163. ##
  1164. # Move the current topic branch, a.k.a. rename it.
  1165. #
  1166. # Example:
  1167. #
  1168. # git topic-move hello
  1169. #
  1170. # This implementation does these:
  1171. #
  1172. # 1. Move the local branch.
  1173. # 2. Move the remote branch by pushing to origin.
  1174. #
  1175. # Customize this alias as you like for your own workflow.
  1176. ##
  1177. topic-move = "!f(){ \
  1178. new_branch=\"$1\"; \
  1179. old_branch=$(git branch-name); \
  1180. git branch --move \"$old_branch\" \"$new_branch\"; \
  1181. git push origin \":$old_branch\" \"$new_branch\"; \
  1182. };f"
  1183. ##########################################################################
  1184. ##
  1185. # Git aliases suitable for particular software integrations and tooling,
  1186. # such as other version control system e.g. CVS, Subversion, etc.
  1187. ##
  1188. ### CVS ALIAS ###
  1189. cvs-i = cvsimport -k -a
  1190. cvs-e = cvsexportcommit -u -p
  1191. ### GitK ###
  1192. # show conflicting merge in gitk:
  1193. gitk-conflict = !gitk --left-right HEAD...MERGE_HEAD
  1194. # show full history in gitk (including "deleted" branches and stashes)
  1195. gitk-history-all = !gitk --all $( git fsck | awk '/dangling commit/ {print $3}' )
  1196. ### Ruby on Rails ###
  1197. # Do everything we can to synchronize all changes for a Ruby On Rails app.
  1198. # We like using rebase (instead of merge), bundle for gems, and rake db:migrate
  1199. rails-get = !"git pull --rebase; git submodule update --init --recursive; bundle check || bundle install; bundle exec rake db:migrate; bundle exec rake db:test:prepare"
  1200. ### Subversion ###
  1201. svn-b = svn branch
  1202. svn-m = merge --squash
  1203. svn-c = svn dcommit
  1204. svn-cp = !GIT_EDITOR='sed -i /^git-svn-id:/d' git cherry-pick --edit
  1205. ##########################################################################
  1206. ##
  1207. # Git aliases to correct common typing mistakes, which git built-in autocorrection
  1208. # does not handle
  1209. ##
  1210. ### Use with shell alias `gitp = git` ###
  1211. ull = pull
  1212. ush = push