From c5a3304954e31b8cdf57061e01d9e9e04b20313a Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 1 Oct 2025 18:06:36 -0600 Subject: [PATCH 1/4] Add `git-review-commits` Add `git-review-commits` Signed-off-by: Joe Block --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6916bcdaf..e659135a3 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ If you wrote one of these scripts and want it removed from this collection, plea | `git-plotrepo` | Matthew McCullogh's [scripts collection](https://github.com/matthewmccullough/scripts/blob/master/git-plotrepo.rb) | Uses dot to draw a graph of the repository. | | `git-pr-fetch` | Joe Block | Fetch PR branches by refspec from one of a repository's remotes. | | `git-pr-list` | Joe Block | Lists pull requests. Requires `gh`. | +| `git-preview-commits` | Julia Evans'[blog](https://jvns.ca/til/fzf-review-git-commits/) | Use [fzf](https://github.com/junegunn/fzf) topreview commits | | `git-promote` | Trevor's **Improving My git Workflow** blog post (404 now) | Promotes a local topic branch to a remote tracking branch of the same name. | | `git-prune-branches` | Michael Demmer in [jut-io/git-scripts](https://github.com/jut-io/git-scripts/blob/master/bin/git-prune-branches) | Deletes each fully merged branch after prompting for confirmation, than asks if you want the deleted branches deleted from your upstream remotes. | | `git-pruneall` | Ryan Tomayko's dotfiles | Prune branches from specified remotes, or all remotes when no remote is specified. | @@ -309,6 +310,7 @@ If you aren't using any ZSH frameworks, or if you're using `bash`, `fish` or ano - [commit-helper](https://github.com/andre-filho/commit-helper) - A python script that helps you write commits following commit conventions. - [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy) - Better looking `git` diffs. - [dunk](https://github.com/darrenburns/dunk) - Another tool for prettier `git` diffs. +- [fzf-git-worktree](https://github.com/banyan/zsh-fzf-git-worktree) - Manage `git` worktrees with [fzf](https://github.com/junegunn/fzf) integration. - [gig](https://dev.to/shihanng/gig-a-gitignore-generator-opc) - a CLI `.gitignore` generator - [git ZSH plugin](https://github.com/davidde/git) - A replacement for the stock oh-my-zsh `git` plugin. Provides quite a few useful aliases and functions that are more consistent in their naming that the relatively unintuitive ones in the stock plugin. - [git-absorb](https://github.com/tummychow/git-absorb) - Essentially, when your working directory has uncommitted changes on top of draft changesets, you can run `git absorb` and the uncommitted modifications are automagically folded ("absorbed") into the appropriate draft ancestor commits. The command essentially looks at the lines that were modified, finds a commit modifying those lines, and amends that commit to include your uncommitted changes. If the changes can't be made without conflicts, they remain uncommitted. This workflow is insanely useful for things like applying review feedback. From ac1552a2f4fc732137ac603af77fb719bc4ba7cc Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 1 Oct 2025 18:14:45 -0600 Subject: [PATCH 2/4] Update pre-commit to v6 Signed-off-by: Joe Block --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ed4162209..fb25f9944 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: check-added-large-files - id: check-executables-have-shebangs From d02a056fa5fd985b795879ca564a7492de90b884 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 1 Oct 2025 18:29:48 -0600 Subject: [PATCH 3/4] Add uncommitted changes Of course I realized _after_ merging the PR Signed-off-by: Joe Block --- README.md | 2 +- bin/git-review-commits | 71 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 bin/git-review-commits diff --git a/README.md b/README.md index e659135a3..298e79649 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ If you wrote one of these scripts and want it removed from this collection, plea | `git-plotrepo` | Matthew McCullogh's [scripts collection](https://github.com/matthewmccullough/scripts/blob/master/git-plotrepo.rb) | Uses dot to draw a graph of the repository. | | `git-pr-fetch` | Joe Block | Fetch PR branches by refspec from one of a repository's remotes. | | `git-pr-list` | Joe Block | Lists pull requests. Requires `gh`. | -| `git-preview-commits` | Julia Evans'[blog](https://jvns.ca/til/fzf-review-git-commits/) | Use [fzf](https://github.com/junegunn/fzf) topreview commits | +| `git-review-commits` | Julia Evans'[blog](https://jvns.ca/til/fzf-preview-git-commits/) | Use [fzf](https://github.com/junegunn/fzf) topreview commits | | `git-promote` | Trevor's **Improving My git Workflow** blog post (404 now) | Promotes a local topic branch to a remote tracking branch of the same name. | | `git-prune-branches` | Michael Demmer in [jut-io/git-scripts](https://github.com/jut-io/git-scripts/blob/master/bin/git-prune-branches) | Deletes each fully merged branch after prompting for confirmation, than asks if you want the deleted branches deleted from your upstream remotes. | | `git-pruneall` | Ryan Tomayko's dotfiles | Prune branches from specified remotes, or all remotes when no remote is specified. | diff --git a/bin/git-review-commits b/bin/git-review-commits new file mode 100755 index 000000000..d4ab49ef5 --- /dev/null +++ b/bin/git-review-commits @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# +# bin/git-review-commits +# +# Based on https://jvns.ca/til/fzf-preview-git-commits/ + +set -o pipefail +if [[ -n "$DEBUG" ]]; then + # shellcheck disable=SC2086 + if [[ "$(echo $DEBUG | tr '[:upper:]' '[:lower:]')" == "verbose" ]]; then + set -x + fi +fi + +function echo-stderr() { + printf '%s +' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way. +} + +function debug() { + if [[ -n "$DEBUG" ]]; then + echo-stderr "$@" + fi +} + +function fail() { + echo-stderr "$1" + exit "${2-1}" ## Return a code specified by $2 or 1 by default. +} + +function has() { + # Check if a command is in $PATH + which "$@" > /dev/null 2>&1 +} + +function check-dependency() { + if ! (builtin command -V "$1" >/dev/null 2>&1); then + fail "missing dependency: can't find $1 in your PATH" + fi +} + +function check-dependencies() { + debug "Checking dependencies..." + # shellcheck disable=SC2041 + # Placeholders for whatever programs you really need + for dep in "$@" + do + if ! has "$dep"; then + fail "Can't find $dep in your $PATH" + else + debug "- Found $dep" + fi + done +} + +# If you need to restrict to a specific os, use +# only-run-on Darwin +# or +# only-run-on Linux + +# Placeholders for your script's real dependencies +check-dependencies fzf git grep + +commit=${1:-HEAD} +git show --stat=120 --format="" "$commit" | \ + grep -E '^\s*\S+.*\|' | \ + fzf --ansi \ + --disabled \ + --bind 'j:down,k:up,q:abort' \ + --preview="echo {} | sed 's/|.*//' | xargs -I% git show --color=always $commit -- %" \ + --preview-window=right:60% \ No newline at end of file From 389e823f0c851f6f0a9d9066f24cb7b695d144db Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 00:30:30 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bin/git-review-commits | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-review-commits b/bin/git-review-commits index d4ab49ef5..9b5fc9dfe 100755 --- a/bin/git-review-commits +++ b/bin/git-review-commits @@ -68,4 +68,4 @@ git show --stat=120 --format="" "$commit" | \ --disabled \ --bind 'j:down,k:up,q:abort' \ --preview="echo {} | sed 's/|.*//' | xargs -I% git show --color=always $commit -- %" \ - --preview-window=right:60% \ No newline at end of file + --preview-window=right:60%