Idiomdrottning’s homepage

NIH with a ribbon bookmark

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.

Follow-ups

Gustav writes in:

I don’t think this is that uncommon (unfortunately). There was a thread on Hacker News about that some time ago.

Yeah, I’ve had it happen a couple of times. It usually doesn’t happen which is great.♥︎

Kensanata writes:

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. 👍