💾 Archived View for idiomdrottning.org › nih-with-a-ribbon-bookmark captured on 2024-05-12 at 15:22:43. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-02-05)
-=-=-=-=-=-=-
Sometimes you get a contribution to your git project and you love their idea but you want to implement things your own way because you’ve got NIH.
Here’s how to do it politely so they still get credit in the git log.
1. Apply their patch or PR in a way that makes them the author in the git log. For PRs that’s straight-forward and for patch application it’s also something that git am can do automatically.
2. Then run git restore --source HEAD^ . (if their change is more than one commit deep, add more ^ or just supply the commit hash or branch name for your own latest change). Or if you're scared of git commands, instead just copy the source files over from another copy of the repo that's set to the version you made.
3. Now their commit is still the most recent commit, but the working tree ("working tree" is git's fancy name for the actual files you're hacking on) reflect the code state before they sent their patch. Now you can implement their idea your own way without their goofy way borking up your code. They’ll still get credit in the log.
The reason I write this is that I recently sent a PR to someone and he instead implemented it his own way, changing the name of my newly introduced option to something that better suited him and so on. As is his right, but it was a li’l rude that I got erased out of the commit history even though it felt to me that he was pretty much only doing a search-and-replace on my version.
Luckily, in that case, he also changed an or to an and so the commit didn’t work and it all went to nought in the end. Doomsday averted!
I don’t think this is that uncommon (unfortunately). There was a thread on Hacker News about that some time ago:
I got robbed of my first kernel contribution
Yeah, I’ve had it happen a couple of times. It usually doesn’t happen which is great.♥︎
I think I got this piece of advice from some website or book online: when you get a merge request, it’s better to merge it and to then revert it, or change it. In their case, the explanation was that it wards off discussion and reimplementations because the thing you didn’t want was in the project history and got removed again, with commit comments explaining what happened. Your point has me more committed than ever to do just that. And I also try to add author credentials when somebody just sends me a suggestion without it being a regular patch. Get those names into the project history. 👍