From 48544b6cfd8e80bcf3aa54f53d5e93ee976f00e0 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sun, 11 Jun 2017 09:11:45 -0600 Subject: [PATCH 1/6] Add git-comma script git-comma will let you add & commit (comma) a new file to your repo in one command --- README.md | 1 + bin/git-comma | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 bin/git-comma diff --git a/README.md b/README.md index de1b92d04..26f484219 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi | `git-changes` | Michael Markert's [dotfiles](https://github.com/cofi/dotfiles) | List authors in the repo in descending commit-count order | | `git-churn` | Gary Bernhardt's [dotfiles](https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn) | Show which files are getting changed most often in the repository | | `git-clone-subset` | Rodrigo Silva (MestreLion) | Uses `git clone` and `git filter-branch` to remove from the clone all files but the ones requested, along with their associated commit history. | +| `git-comma` | Christian Neukirchen's [blog](http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html) | Adds and commits a file in one command | | `git-conflicts` | Seth Messer's [bits and bobs](https://github.com/megalithic/bits-and-bobs/) repo | Show files with conflicts | | `git-copy-branch-name` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Copy the current branch name to the clipboard (OS X Only) | | `git-credit` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Quicker way to assign credit to another author on the latest commit| diff --git a/bin/git-comma b/bin/git-comma new file mode 100755 index 000000000..a200447c2 --- /dev/null +++ b/bin/git-comma @@ -0,0 +1,18 @@ +#!/usr/bin/env zsh +# +# git comma - like git commit, but adds unknown files automatically +# +# Source: http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html + +added=() + +# add unknown files... +for arg; do + if [[ -f $arg && -n $(git ls-files -o $arg) ]]; then + git add $arg + added+=($arg) + fi +done + +# ...reset them when commit is aborted +git commit ${@:+-o} "$@" || git reset -q -- $added From 038ddb47edbf97e8516a7f0ccd2fc0352b78a0df Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sun, 11 Jun 2017 09:19:43 -0600 Subject: [PATCH 2/6] Add Christian's git-attic script. There are times I would have killed to have something like this. --- README.md | 1 + bin/git-attic | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 bin/git-attic diff --git a/README.md b/README.md index 26f484219..717507add 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi | Script | Original Source | Description | | ------ | --------------- | ----------- | +| `git-attic` | Christian Neukirchen's [blog](http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html) | Displays a list of deleted files in your repo. The output is designed to be copy’n’pasted: Pass the second field to git show to display the file contents, or just select the hash without ^ to see the commit where removal happened. | | `git-big-file` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Show files in the repo larger than a threshold size | | `git-change-author` | Michael Demmer in [jut-io/git-scripts](https://github.com/jut-io/git-scripts/blob/master/bin/git-change-author) | Change one author/email in the history to another | | `git-change-log` | John Wiegley's [git-scripts](https://github.com/jwiegley/git-scripts) | turn `git log` output into a complete Changelog for projects that haven't been maintaining one | diff --git a/bin/git-attic b/bin/git-attic new file mode 100755 index 000000000..318283fb1 --- /dev/null +++ b/bin/git-attic @@ -0,0 +1,18 @@ +#!/bin/sh +# git-attic [-M] [PATH] - list deleted files of Git repositories +# +# Use -M to not show renamed files, and other git-log options as you like. +# +# The output is designed to be copy’n’pasted: Pass the second field to +# git show to display the file contents, or just select the hash without ^ to +# see the commit where removal happened +# +# Source: http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html + + +git log --raw --no-renames --date=short --format="%h %cd" "$@" | + awk '/^[0-9a-f]/ { commit=$1; date=$2 } + /^:/ && $5 == "D" { print date, commit "^:" $6 }' | + git -p column + +set -o pipefail From c1a8ddf01fbb746e2d54eb13b5bab79914ed95c4 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sun, 11 Jun 2017 09:26:02 -0600 Subject: [PATCH 3/6] Recredit git-trail Found the original author of the `git-trail` script in Daniel's dotfiles while adding scripts from Christian's blog. --- README.md | 2 +- bin/git-trail | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 717507add..1e883eebc 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi | `git-submodule-rm` | Greg V's [dotfiles](https://github.com/myfreeweb/dotfiles) | Allows you to remove a submodule easily with `git submodule-rm path/to/submodule` | | `git-thanks` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | List the contributors to a repository in descending commit order, even if their contribution has been completely replaced | | `git-track` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Sets up your branch to track a remote branch. Assumes you mean origin/localbranchname | -| `git-trail` | Daniel Hahler's [dotfiles](https://github.com/blueyed/dotfiles/blob/master/usr/bin/git-trail) | Show all branching points in the repo's Git history | +| `git-trail` | Christian Neukirchen's [blog](http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html) | Show all branching points in the repo's Git history | | `git-undo-push` | ? | Undoes your last push to branch ($1) of origin | | `git-unpushed` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Show the diff of everything you haven't pushed to the origin remote yet | | `git-unreleased` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Shows git commits since the last tagged version | diff --git a/bin/git-trail b/bin/git-trail index 6b65eda5b..8b18fd935 100755 --- a/bin/git-trail +++ b/bin/git-trail @@ -1,6 +1,6 @@ #!/bin/sh -e # -# https://github.com/blueyed/dotfiles/blob/master/usr/bin/git-trail +# http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html # # git trail [-r] [-t] [COMMIT] - show all branching points in Git history @@ -22,5 +22,5 @@ COMMIT=$(git rev-parse --no-flags --default HEAD "$@") "git name-rev --name-only --refs=\"" mbs[i] "\" " $3 | getline nr if (nr != "undefined") print $1, $2, nr # skip unreachable commits } - } + } }' | git -p column # paginate output From 9de16221cb0c93d5ee468bb5866713388f67f500 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sun, 11 Jun 2017 09:32:02 -0600 Subject: [PATCH 4/6] Update git-trail description per Christian's blog --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e883eebc..90de166eb 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi | `git-submodule-rm` | Greg V's [dotfiles](https://github.com/myfreeweb/dotfiles) | Allows you to remove a submodule easily with `git submodule-rm path/to/submodule` | | `git-thanks` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | List the contributors to a repository in descending commit order, even if their contribution has been completely replaced | | `git-track` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Sets up your branch to track a remote branch. Assumes you mean origin/localbranchname | -| `git-trail` | Christian Neukirchen's [blog](http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html) | Show all branching points in the repo's Git history | +| `git-trail` | Christian Neukirchen's [blog](http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html) | Show all branching points in the repo's Git history so you can see how to reach commits in the current branch from other branches | | `git-undo-push` | ? | Undoes your last push to branch ($1) of origin | | `git-unpushed` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Show the diff of everything you haven't pushed to the origin remote yet | | `git-unreleased` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Shows git commits since the last tagged version | From 738c36819f253573536e93f51d8d5fd15c460346 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sun, 11 Jun 2017 09:35:32 -0600 Subject: [PATCH 5/6] Add Christian's git-neck script --- README.md | 1 + bin/git-neck | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100755 bin/git-neck diff --git a/README.md b/README.md index 90de166eb..d9f9f2a34 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi | `git-ls-object-refs` | Ryan Tomayko's [dotfiles](https://github.com/rtomayko/dotfiles) | Find references to an object with SHA1 in refs, commits, and trees. All of them. | | `git-maxpack` | John Wiegley's [git-scripts](https://github.com/jwiegley/git-scripts) | Compress a repo's pack files as much as possible | | `git-move-commits` | Corey Oordt's [git-scripts](https://github.com/coordt/git-scripts/blob/master/git-move-commits) | `git move-commits num-commits correct-branch` moves the last n commits to correct-branch (creating it if necessary) | +| `git-neck` | Christian Neukirchen's [blog](http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html) | Show commits from the HEAD until the first branching point. Companion script for `git-trail` | | `git-nuke` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Nukes a branch locally and on the origin remote | | `git-object-deflate` | Ryan Tomayko's [dotfiles](https://github.com/rtomayko/dotfiles) | Deflate an loose object file and write to standard output | | `git-outgoing` | Michael Markert's [dotfiles](https://github.com/cofi/dotfiles) | Show commits that are on the local branch that have not been pushed to the tracking branch | diff --git a/bin/git-neck b/bin/git-neck new file mode 100755 index 000000000..e8ad87d9c --- /dev/null +++ b/bin/git-neck @@ -0,0 +1,14 @@ +#!/bin/sh -e +# git neck [-r] [COMMIT] - show commits until first branching point +# +# Source: http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html + +[ "$1" = -r ] && shift && R=-r +COMMIT=$(git rev-parse --no-flags --default HEAD "$@") + +# skip first elements of trail +TORSO=$(git trail $R $COMMIT | cut -d' ' -f2 | uniq | sed -n 2p) + +# fall back to initial commit on empty trail +: ${TORSO:=$(git rev-list --max-parents=0 HEAD)} +git log --oneline $(git rev-parse --no-revs "$@") $COMMIT...$TORSO From 269adf2896f1da30488774e1622459227b2df2dc Mon Sep 17 00:00:00 2001 From: Joe Block Date: Sun, 11 Jun 2017 09:38:19 -0600 Subject: [PATCH 6/6] Add Christian's blog post to the external resources section. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d9f9f2a34..b8bbc6677 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,8 @@ Here are some helpful aliases for your `~/.gitconfig` * [git-tips/tips](https://github.com/git-tips/tips) is a collection of git tips +* Christian Neukirchen wrote a great [blog post](http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html) on git that is the source for several scripts in this collection. + * Mislav Marohnić has a good article on git tips on his [blog](http://mislav.net/2010/07/git-tips/). Several of his git scripts are in this collection. * And when you manage to get your git working directory in a sad state, you can run into the chicken-egg problem where if you just knew what command to man, you could dig yourself out of the hole, but if you knew that, you wouldn't be in the bad place anyway. [Oh Shit, Git!](http://ohshitgit.com/) has a collection of bad situations explained in plain English and how to get yourself out of them.