Skip to content

Instantly share code, notes, and snippets.

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 KharmaScribbles/89fda522f1b8c2ad87312626b777e17f to your computer and use it in GitHub Desktop.
Save KharmaScribbles/89fda522f1b8c2ad87312626b777e17f to your computer and use it in GitHub Desktop.
Cherry-picks commits from master that have changes to specified files.
$!/usr/bin/env sh
branch=`git symbolic-ref --short HEAD`
git checkout master
commits=`git log --pretty="%H" --reverse -- $*`
git checkout $branch
for commit in $commits; do
git cherry-pick $commit
done
@KharmaScribbles
Copy link
Author

Usage:

Create the clean branch:

$ git checkout --orphan my-new-branch
$ git rm -rf .
Create an initial commit, because cherry-pick doesn't work on an empty head.

$ touch .dummy-file
$ git add .dummy-file
$ git commit -m "Initial commit"

Now, assuming you're still in the "my-new-branch" branch, run

$ git-pick-file.sh file1 file2 fileX
Then to make sure everything worked as planned, check

$ git log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment