Reputation: 575
I have an old commit I'd like to cherry-pick onto another branch. However, since it's an old commit there could be mistakes in it that have been fixed by more recent commit. I know it's not flawless, but if I could get a list of the commits that modify the code that was added, that would probably catch any such changes.
I can't go through individual commits since the original because there are too many of them, but the smaller list I described should be manageable.
An example of what I'm looking for:
base:
void foo() {
//do something
}
after commit1:
void foo() {
//do something
}
bool bar() {
return true;
}
after commit2:
bool foo() {
//do something
return false;
}
bool bar() {
return true;
}
after commit3:
bool foo() {
//do something
return false;
}
bool bar() {
if (cond)
return false;
return true;
}
if commit1 is the old commit I'm interested in cherry-picking, I should get a list containing commit3, but not commit2.
Edit: To clarify a little further in response to @ObsidianAge's comment, I'll give an example of the cherry-pick.
if the commit history looks like this:
* c470ee1 - commit3 (branch1)
* c65a8d0 - commit2
| * fe51fc2 - commitB (HEAD -> branch2)
| * 900ca02 - commitA
* | 607e2c7 - commit1
|/
* Base
Then cherry-pick command would be git cherry-pick 607e2c7
. However, since commit3 is a fix for a mistake from commit1, the result would be that branch2 now contains the mistake from commit1, but not the fix for it.
Since commit3 modifies the block of 3 lines which commit1 added, this should get it flagged as relevant. On the other hand, commit2 doesn't touch those 3 lines, and should not get flagged as relevant.
I'm aware that it's rather unlikely there is a git porcelain command for this, but I'm hoping there's a way of accomplishing this by combining git plumbing commands and/or terminal commands like sed.
Upvotes: 1
Views: 149
Reputation: 1328522
As seen in "how do I view the change history of a method/function?", you could use a git log -L :<funcname>:<file>
That would help trace the commits which have modified a particular function.
Upvotes: 1