Skip to content

Instantly share code, notes, and snippets.

@peterdietz
Created October 5, 2010 22:56
Show Gist options
  • Save peterdietz/612507 to your computer and use it in GitHub Desktop.
Save peterdietz/612507 to your computer and use it in GitHub Desktop.
Preserve git commit history between two unrelated projects -- http://wingolog.org/archives/2008/10/14/merging-in-unrelated-git-branches
#!/bin/bash
set -e
if test -z "$2" -o -n "$3"; then
echo "usage: $0 REPO BRANCHNAME" >&2
exit 1
fi
repo=$1
branch=$2
git fetch "$repo" "$branch"
head=$(git rev-parse HEAD)
fetched=$(git rev-parse FETCH_HEAD)
headref=$(git rev-parse --symbolic-full-name HEAD)
git checkout $fetched .
tree=$(git write-tree)
newhead=$(echo "merged in branch '$branch' from $repo" | git commit-tree $tree -p $head -p $fetched)
git update-ref $headref $newhead $head
git reset --hard $headref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment