Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cherry pick only commits that touch a particular file

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?

like image 884
gcbenison Avatar asked Feb 10 '14 18:02

gcbenison


1 Answers

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.

like image 200
Learath2 Avatar answered Nov 09 '22 03:11

Learath2