Skip to content

Instantly share code, notes, and snippets.

@giggio
Last active May 6, 2021 15:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giggio/6d898821a1f5b10a9142bb60c04fc3af to your computer and use it in GitHub Desktop.
Save giggio/6d898821a1f5b10a9142bb60c04fc3af to your computer and use it in GitHub Desktop.
Copy a commit from any repo to any other repo
# copy a single commit
git --no-pager --git-dir=<original_dir>/.git format-patch -k -1 --no-color --stdout <commit_sha> | git am -3 -k --ignore-whitespace
# copy a whole repo (branch main, change accordingly):
GIT_DIR=<original_dir>/.git # change to correct dir
for ID in `git --no-pager --git-dir=$GIT_DIR rev-list main | tac`; do
git --no-pager --git-dir=$GIT_DIR format-patch -k -1 --no-color --stdout $ID | git am -3 -k --ignore-whitespace
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment