Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take lines from someone's code via Git so that they are credited in commit history?

Tags:

git

In my case, I have a file, it came long ago from a fork of something else. Tons of things have diverged. However, I notice a small change in another fork that I like. I want to use that code. I could just copy and paste and commit, but then it would look like I wrote it. I could add a comment in the commit about the original author, but that's not ideal.

In this case, all the code I want came from a single commit that had nothing else in it. I can't easily cherry-pick because my code is changed enough that all the lines are different. But what I want to do is get the exact lines from their commit with credit to them, and just merge in those select lines to a file in my code where they will be different line numbers in a longer file. Is this feasible?

like image 554
wolftune Avatar asked Jan 31 '26 02:01

wolftune


1 Answers

Why don't you do whatever to compose the commit (probably apply patch from that other commit) and then when you commit locally, use the --author= < originalAuthor > flag and specify the original author's name, so the commit is attributed to them?

like image 119
DavidN Avatar answered Feb 01 '26 18:02

DavidN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!