Created
April 14, 2016 10:59
-
-
Save tsayen/f1c1c4d62d4fda77abf1586bd39f9b74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Usage: | |
# ./git-move.sh path/to/file/or/dir path/to/destination/repo | |
echo "creating patch for path ${1}" | |
git log --name-only --pretty="format:" --follow "${1}" \ | |
| sort -u | \ | |
xargs git log --pretty=email --patch-with-stat --reverse --full-index --binary -m --first-parent -- > "${2}/_patch_" \ | |
&& echo "moving to destination repo at ${2}" \ | |
&& cd "${2}" \ | |
&& echo "applying patch" \ | |
&& git am --committer-date-is-author-date < _patch_ \ | |
&& echo "OK" |
I ended up using some of this, but in this form that supports multiple files, as well a deleted/renamed files:
cd repository
git log --pretty=email --patch-with-stat --reverse --full-index --binary -m --first-parent -- ./folder ./file1.txt ./file2.txt ./deleted_file.txt > ~/tmp/hist.patch
cd ../another_repository
git am --committer-date-is-author-date < ~/tmp/hist.patch
Thanks, tsayen. I expanded on this a bit to meet my local needs -- https://github.com/wesgarland/git-relocate
I liked the @dflock's version, but I wanted to keep the detailed history (not just merges), so I removed --first-parent
and added --no-merges
to the git-log invocation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked beautifully. Thank you!