0

It's simple to git cherry-pick other commits from other branches, all while maintaining a clean git blame history.

If I'm UserA working on branch-A, and then I know in an experimental branch-B, UserB and UserC had been hacking away over the course of hundreds of commits on FunctionC that I want to pull in. There are way too many commits to apply, and all those commits might have other changes I don't want to pull in.

Whats the most idiomatic way I can pull in FunctionC in a way that preserves the history that went into it?

I've been searching for quite awhile, but in the case the changes I want weren't cleanly available in a few commits, it didn't seem like there was a way. All other methods seem to lose track of history. In the meantime I've just been basically doing the equivalent of copy/pasting via git checkout --patch branch-B but it leaves no sense of the activity that went into it, or whom to check the git blame for it, other than UserA.

ozhou
  • 105
  • 6

1 Answers1

1

Whats the most idiomatic way I can pull in FunctionC in a way that preserves the history that went into it?

There is only one source of history in Git. History, in Git, is commits. Commits are the history. That's all there is.

If you ask about file history or line history, Git will synthesize something from the commit history. A future or hypothetical annotation command could, perhaps, be told look at commit X for some appropriate X that is not the current commit and not an immediate parent of the current commit, but the existing tools work by, when given a commit, looking at that commit's parent (or for a merge commit, parents plural), then looking at the parent's parent, and so on.

That's why you have not found anything satisfactory. Either those commits, with their history, are part of your commits' history—are predecessors of your current commit—or they're not. If they're not, git blame won't look at them.

Note that you can, for as long as you like, use git replace to fake up a history. You might be able to grab the functions you want and use git replace to put in a fake merge so that git blame can walk back to both the real parent, and the commit from which you grabbed the file. But there are a lot of caveats with replacement commits. The advantage is that you can remove the replacements; the biggest disadvantage is that they're not cloned by default.

torek
  • 448,244
  • 59
  • 642
  • 775