Skip to content

Commit 2babdfa

Browse files
authored
Merge pull request #43 from unixorn/add-scripts-from-chris-blog
Add scripts from Christian's blog
2 parents 984f598 + 269adf2 commit 2babdfa

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi
7878

7979
| Script | Original Source | Description |
8080
| ------ | --------------- | ----------- |
81+
| `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. |
8182
| `git-big-file` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Show files in the repo larger than a threshold size |
8283
| `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 |
8384
| `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 |
8485
| `git-changes` | Michael Markert's [dotfiles](https://github.com/cofi/dotfiles) | List authors in the repo in descending commit-count order |
8586
| `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 |
8687
| `git-clone-subset` | Rodrigo Silva (MestreLion) <linux@rodrigosilva.com> | Uses `git clone` and `git filter-branch` to remove from the clone all files but the ones requested, along with their associated commit history. |
88+
| `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 |
8789
| `git-conflicts` | Seth Messer's [bits and bobs](https://github.com/megalithic/bits-and-bobs/) repo | Show files with conflicts |
8890
| `git-copy-branch-name` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Copy the current branch name to the clipboard (OS X Only) |
8991
| `git-credit` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Quicker way to assign credit to another author on the latest commit|
@@ -106,6 +108,7 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi
106108
| `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. |
107109
| `git-maxpack` | John Wiegley's [git-scripts](https://github.com/jwiegley/git-scripts) | Compress a repo's pack files as much as possible |
108110
| `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) |
111+
| `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` |
109112
| `git-nuke` | Zach Holman's [dotfiles](https://github.com/holman/dotfiles) | Nukes a branch locally and on the origin remote |
110113
| `git-object-deflate` | Ryan Tomayko's [dotfiles](https://github.com/rtomayko/dotfiles) | Deflate an loose object file and write to standard output |
111114
| `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 |
@@ -135,7 +138,7 @@ If you aren't using any zsh frameworks, or if you're a bash user, do the followi
135138
| `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` |
136139
| `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 |
137140
| `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 |
138-
| `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 |
141+
| `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 |
139142
| `git-undo-push` | ? | Undoes your last push to branch ($1) of origin |
140143
| `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 |
141144
| `git-unreleased` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Shows git commits since the last tagged version |
@@ -180,6 +183,8 @@ Here are some helpful aliases for your `~/.gitconfig`
180183

181184
* [git-tips/tips](https://github.com/git-tips/tips) is a collection of git tips
182185

186+
* 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.
187+
183188
* 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.
184189

185190
* 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.

bin/git-attic

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
# git-attic [-M] [PATH] - list deleted files of Git repositories
3+
#
4+
# Use -M to not show renamed files, and other git-log options as you like.
5+
#
6+
# The output is designed to be copy’n’pasted: Pass the second field to
7+
# git show to display the file contents, or just select the hash without ^ to
8+
# see the commit where removal happened
9+
#
10+
# Source: http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html
11+
12+
13+
git log --raw --no-renames --date=short --format="%h %cd" "$@" |
14+
awk '/^[0-9a-f]/ { commit=$1; date=$2 }
15+
/^:/ && $5 == "D" { print date, commit "^:" $6 }' |
16+
git -p column
17+
18+
set -o pipefail

bin/git-comma

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env zsh
2+
#
3+
# git comma - like git commit, but adds unknown files automatically
4+
#
5+
# Source: http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html
6+
7+
added=()
8+
9+
# add unknown files...
10+
for arg; do
11+
if [[ -f $arg && -n $(git ls-files -o $arg) ]]; then
12+
git add $arg
13+
added+=($arg)
14+
fi
15+
done
16+
17+
# ...reset them when commit is aborted
18+
git commit ${@:+-o} "$@" || git reset -q -- $added

bin/git-neck

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh -e
2+
# git neck [-r] [COMMIT] - show commits until first branching point
3+
#
4+
# Source: http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html
5+
6+
[ "$1" = -r ] && shift && R=-r
7+
COMMIT=$(git rev-parse --no-flags --default HEAD "$@")
8+
9+
# skip first elements of trail
10+
TORSO=$(git trail $R $COMMIT | cut -d' ' -f2 | uniq | sed -n 2p)
11+
12+
# fall back to initial commit on empty trail
13+
: ${TORSO:=$(git rev-list --max-parents=0 HEAD)}
14+
git log --oneline $(git rev-parse --no-revs "$@") $COMMIT...$TORSO

bin/git-trail

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -e
22
#
3-
# https://github.com/blueyed/dotfiles/blob/master/usr/bin/git-trail
3+
# http://chneukirchen.org/blog/archive/2013/01/a-grab-bag-of-git-tricks.html
44
#
55
# git trail [-r] [-t] [COMMIT] - show all branching points in Git history
66

@@ -22,5 +22,5 @@ COMMIT=$(git rev-parse --no-flags --default HEAD "$@")
2222
"git name-rev --name-only --refs=\"" mbs[i] "\" " $3 | getline nr
2323
if (nr != "undefined") print $1, $2, nr # skip unreachable commits
2424
}
25-
}
25+
}
2626
}' | git -p column # paginate output

0 commit comments

Comments
 (0)