Last active 1735753654

A script to find the first occurrence of something in a git codebase

README.md Raw

gitfindfirst.sh

A shell script for finding the first commit that introduced a search term into a git repository.

Pre-reqs

Installation

  1. Install the pre-reqs
  2. Download gitfindfirst.sh and noack.sh
  3. Place both these sripts in the same directory
  4. Make them both executable (e.g. chmod +x gitfindfirst.sh).

Usage

Given a search term present at HEAD, issue:

gitfindfirst.sh SearchTerm 

Search terms are specified using ack syntax. To search for a single word (e.g. IpcOneShotServer), simply specify that word:

gitfindfirst.sh IpcOneShotServer 
gitfindfirst.sh Raw
1#!/usr/bin/env bash
2set -e
3
4# First check that the search target represented by the ack args are present at HEAD
5ACK_ARGS="$@"
6if ! ack -1 $ACK_ARGS; then
7 echo "Error: search target '$ACK_ARGS' not found at HEAD"
8 echo "Tip: checkout a revision containing the search target and try again."
9 exit 1
10fi
11
12SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
13git bisect start HEAD $(git rev-list --max-parents=0 HEAD)
14git bisect run $SCRIPT_DIR/noack.sh $ACK_ARGS
15git bisect reset
license.txt Raw
1Copyright © 2025 Glyn Normington
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
4files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy,
5modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
6Software is furnished to do so, subject to the following conditions:
7
8The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
11WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
13ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
noack.sh Raw
1#!/usr/bin/env bash
2! ack -1 "$@"