Skip to content

Instantly share code, notes, and snippets.

View peff's full-sized avatar

Jeff King peff

View GitHub Profile
@peff
peff / test
Created August 13, 2010 14:44
#!/bin/sh
# Create a repo with non-linear history.
rm -rf repo
commit() {
echo "$2" >>$1 && git add $1 && git commit -m "$1: $2"
}
push() {
@peff
peff / last-used.sh
Created February 11, 2011 22:00
find the last commit that touched a file
#!/bin/sh
commit=HEAD
pathspec=
git log --format='%H%n %s' --name-status --no-merges --no-renames $commit -- $pathspec |
perl -e '
while(<>) {
if (/^[0-9a-f]{40}$/) {
$sha1 = $&;
@peff
peff / README.md
Created April 28, 2012 11:16
git gc --aggressive case

This is a repository that has been packed over time with "git gc", but repacks from ~245M to ~145M with "git gc --aggressive". To narrow it down, I tried different packing options. With each of the following commands, I get these resulting pack sizes:

  • git repack -ad: 246M
  • git repack -ad -f: 376M
  • git repack -ad --window=250: 246M
  • git repack -ad -f --window=250: 145M
@peff
peff / README.md
Created May 22, 2012 07:26
many-ref repo

This repository has a very large number of refs, which shows some slow-down on certain git operations.

Keybase proof

I hereby claim:

  • I am peff on github.
  • I am peff (https://keybase.io/peff) on keybase.
  • I have a public key whose fingerprint is 22BE 8EED C3C8 C7FC 74A3 CF21 CEF7 0F9B 90F6 F6B8

To claim this, I am signing this object:

@peff
peff / README.md
Last active August 29, 2015 14:16
explanation of merge versus rebase

Rebase conflicts can sometimes be harder than merge conflicts. This is because merges look only at the end points (what you have, and they have, and the merge base). But the rebase will look through each commit of the rebased topic. This can manifest itself in two ways:

  1. You'll get more conflicts in two stretches of code that reach similar endpoints, but get there through differing paths. For example, consider this trivial example:

$ echo base >file && git add file && git commit -m base

@peff
peff / README.md
Last active August 29, 2015 14:21
deadlocked http-backend/apache strace output
@peff
peff / ghpath.sh
Last active March 2, 2017 02:13
convert <file>:<line> into github permalink
#!/bin/sh
#
# Turn a file/line combination into a link to github.com.
# I use this from vim with:
#
# command! Link :exec "!ghpath %:p " . line(".")
#
# Running ":Link" anywhere will get you a link to the current file and
# line number. Remember to drop this as "ghpath" into your PATH, and
# to turn on the executable bit.
@peff
peff / git-du
Last active May 17, 2019 07:43
git-du script
#!/usr/bin/perl
#
# Generate a listing of all paths ever used in the repository, along with the
# disk space used by the path throughout the entire history. Note that sizes
# for trees are cumulative; they include the sizes of all of the paths below
# them, in addition to the tree storage itself. All sizes are in bytes, and
# reflect git's delta and zlib compression.
#
# One caveat is that this is just the _current_ on-disk size. The on-disk size
# of each object may change if git repacks and chooses different delta bases,
@peff
peff / sdl
Last active December 16, 2018 20:36
Hacky perl script to grep for Microsoft's SDL-banned functions.
#!/usr/bin/perl
#
# Usage: git grep -E "$(./sdl banned)" -- '*.c' '*.h'
my @TABLE = (
# Table 1. Banned string copy functions and replacements
BANNED => [qw(
strcpy
strcpyA
strcpyW