Skip to content

Instantly share code, notes, and snippets.

@wpalmer
Created April 7, 2016 16:52
Show Gist options
  • Save wpalmer/9c2aa7907ebbcd096e2df0625176f813 to your computer and use it in GitHub Desktop.
Save wpalmer/9c2aa7907ebbcd096e2df0625176f813 to your computer and use it in GitHub Desktop.
written but not run - merge a single file
#!/bin/bash
TEMP="$(mktemp --tmpdir -d 'git-merge-single.XXXXXXXXXX')"
[ -n "$TEMP" -a -d "$TEMP" -a -w "$TEMP" ] || exit 1
_cleanup(){ rm -rf "$TEMP"; }
trap _cleanup EXIT
their_commit="${1%%:*}"
file="${1#*:}"
git cat-file blob "$their_commit:./$file" > "$TEMP/theirs"
git cat-file blob "$(git merge-base HEAD $their_commit):./$file" > "$TEMP/base"
git merge-file "./$file" "$TEMP/base" "$TEMP/theirs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment