Cherry pick only commits that touch a particular file

git, git-cherry-pick

Solution

`git cherry-pick $(git log --reverse --pretty=format:"%H" filename)`

Should do the trick. `git log --reverse --pretty=format:"%H" filename` basically gives you a newline separated list of SHA's of all commits that modified `filename` in reverse order so the commits merge in the correct order. We then feed the list to git cherry-pick.

`git cherry-pick $(git rev-list --reverse HEAD -- filename)`is another version of the above command provided by Magnus Bäck.

Problem

What is a concise way to request "cherry pick from another branch only the commits that touch a particular file"? i.e. the command `git log ..other-branch afile` gives a list of unmerged commits in other-branch that touch "afile"; how can I request that this same set of commits be replayed on the current branch?

Original source