Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
#Inspired by http://blog.neutrino.es/2012/git-copy-a-file-or-directory-from-another-repository-preserving-history/
#Copy a file or directory out of a git repository, preserving history!
#Creates DESTINATIONPATH with patches that can be applied with git am
#e.g.
#0001-Add-new-theme-Gum.patch
#0002-Add-syntax-highlighting-for-Gum-theme.patch
#0003-Gum-Fix-tag-URLs-not-being-slugified-and-therefore-b.patch
#0004-Gum-Add-Disqus-support.patch
#0005-Gum-Use-article-title-as-the-title-of-the-generated-.patch
#0006-Gum-HTML-escape-tag-names-when-rendering-them.patch
#Usage: copy-git-file.sh /some/repo/interesting/thing /destination/patch/path
#todo, test $1 and $2
DESTINATIONPATH=$2
SOURCE=$1 #first arg to script, either file or dir
pushd $SOURCE
git format-patch -o $DESTINATIONPATH $(git log $SOURCE|grep ^commit|tail -1|awk '{print $2}')..HEAD $SOURCE
popd
@jamischarles

This comment has been minimized.

Copy link
Owner Author

jamischarles commented Apr 1, 2015

You need to manually move the file over FIRST, then run this command

@jamischarles

This comment has been minimized.

Copy link
Owner Author

jamischarles commented Apr 1, 2015

  1. Move/copy file
  2. Then commit the file
  3. git am --ignore-space-change --ignore-whitespace /path/to/patch/file
@jamischarles

This comment has been minimized.

Copy link
Owner Author

jamischarles commented Apr 1, 2015

any problems?

run git rebase --abort
or git am --abort

@jamischarles

This comment has been minimized.

Copy link
Owner Author

jamischarles commented Apr 1, 2015

Q: How do you resolve conflicts?

@jamischarles

This comment has been minimized.

Copy link
Owner Author

jamischarles commented Apr 1, 2015

And what do conflicts look like in an am file?

@jamischarles

This comment has been minimized.

Copy link
Owner Author

jamischarles commented Apr 1, 2015

You can manually change things in the patch files...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.