Skip to content

Instantly share code, notes, and snippets.

@anver
Forked from joeyates/git-copy-file-history.sh
Created April 24, 2021 06:27
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 anver/ac170600b02158ac38913f2ddd645364 to your computer and use it in GitHub Desktop.
Save anver/ac170600b02158ac38913f2ddd645364 to your computer and use it in GitHub Desktop.
Copy a commits from one Git repo to another
# Copy all modifications to a file from one repo to another
for c in `git --git-dir=../path/to/repo/.git log --reverse --pretty=tformat:"%H" -- path/to/file`; do
git --git-dir=../path/to/repo/.git format-patch --keep-subject -1 --stdout $c | git am --3way --keep;
done
# Copy a single commit from one repo to another
git --git-dir=../path/to/repo/.git format-patch --keep-subject -1 --stdout COMMIT | git am --3way --keep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment