Wiedi in Wonderland

Take half a pull request and keep the author

Thu 25 September 2014

So someone contributes a fantastic bugfix to your project on github and you're happy. But there's a problem: besides the bugfix there are other changes too that you might not want to merge.

So what you do is you start cherry-picking the good stuff. On Stackoverflow there is actually a great answer on how to only cherry-pick some changes from one commit. Sadly, once you do it like in that answer you become the author of that new commit.

Someone took the effort to write a fix for your project so proper attribution is important. The solution is git commit -c <commit> which reuses the log message and the authorship information (including the timestamp) when creating the commit.

So the complete thing looks something like that:

git cherry-pick -n <commit> # get your patch, but don't commit (-n = --no-commit)
git reset                   # unstage the changes from the cherry-picked commit
git add -p                  # make all your choices (add the changes you do want)
git commit -c <commit>      # make the commit and keep the author