Skip to content

Instantly share code, notes, and snippets.

@panzi
Last active November 20, 2018 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panzi/a79014fc5696647ff8db3f2bfc55e69a to your computer and use it in GitHub Desktop.
Save panzi/a79014fc5696647ff8db3f2bfc55e69a to your computer and use it in GitHub Desktop.
Merge files useing kdiff3. Using git mergetool merges files one by one, this opens all files in kdiff3 at once. TODO: somehow git add merged files after kdiff3 exists
#!/bin/bash
set -e
SUBDIRECTORY_OK=1
. "`git --exec-path`/git-sh-setup"
cd_to_toplevel
O=".git-kmerge3-tmp-$$"
list=$O/.git-kmerge3-list
trap "rm -rf $O" 0
mkdir $O
remote="$1"
if [[ $remote = "" ]]; then
echo "git-kmerge3 <tree-ish>">&2
exit 1
fi
local=`git rev-parse HEAD`
base=`git merge-base "$local" "$remote"`
git archive --prefix=local/ "$local" | tar x -C $O
git archive --prefix=remote/ "$remote" | tar x -C $O
git archive --prefix=base/ "$base" | tar x -C $O
git merge "$remote" || kdiff3 -m "$O/base" "$O/local" "$O/remote" --out . --L1 Base --L2 Local --L3 Remote || git merge --abort
# TODO: somehow git add merged files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment