Skip to content

Instantly share code, notes, and snippets.

@michitux
Last active March 11, 2023 21:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michitux/f7fdb2c36e728887b411e9aecb8e52ff to your computer and use it in GitHub Desktop.
Save michitux/f7fdb2c36e728887b411e9aecb8e52ff to your computer and use it in GitHub Desktop.
Export a series of git commits into patches.
# Inspired by http://blog.worldofcoding.com/2013/03/formatting-git-patches-for-partially.html
# This calls git log to get a list of commits that affect a certain file pattern and then exports each of them into a file
# If the exported commits shall be limited to these files, another pathspec could be added in the second git log call.
# The code is split into several lines to make it more readable, but all ";" are there such that all line breaks could be removed.
c=0;
git log --oneline --reverse -- your/pathspec.* |cut -d' ' -f1 | while read a;
do
c=$[c+1];
n=$(printf "%04d\n" $c);
git log -p --pretty=email --stat -m --first-parent $a~1..$a > $n-$a.patch;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment