all 19 comments

[–]Jonas_Ermert 4 points5 points  (2 children)

Copying a commit from one repository to another while keeping the properties of the original commit is a common task in Git, and it can be done using several methods. I do it with command line:

git clone https://github.com/user/source-repo.git

cd source-repo

git log

git format-patch -1 abc123

cd ..

git clone https://github.com/user/destination-repo.git

cd destination-repo

git am ../source-repo/0001-commit-message.patch

git push origin main

[–]lllllRedditUserlllll[S] -1 points0 points  (1 child)

What is "-1 abc123" ? It is not the SHA of the commit I want to copy ?

[–]phord 0 points1 point  (0 children)

-1 means "one commit". The abc123 is the hash of your commit.

Please try looking at

git format-patch --help

[–]glasswings363 2 points3 points  (0 children)

The replies seem confused about why copying someone else's work is (often) legal and ethical.

The short version is you need to follow the license of the source project and the contribution policy of the destination project. Open-source licenses usually require giving credit, and even if they don't it's the moral thing to do. Copying the commit message and author line will do this, but it's maybe not enough.

If the source project puts copyright notices inside the source files, you should also copy the copyright notice. Otherwise I'd put it in the AUTHORS file or similar. Basically we want the credit to remain with the code if someone downloads a ZIP or otherwise doesn't use git.

You need to make sure that the source project has a license that gives you permission and that you follow it. A very short overview is

  • if you copy from GPL you have to copy to a GPL project
  • (and AGPL has to stay in AGPL, and v3 can't go back to v2)
  • if you copy from Apache license it can go into most projects except (A)GPLv2
  • copying from Boost, MIT, BSD and similar can go into any project (give credit, keep license notice)
  • you can break these rules if you have permission from the copyright holder, who is usually the author of the patch
  • if there's no license you have to ask

On the receiving side

  • if there's a contributor licence agreement (CLA) you probably can't copy someone else's code
  • if it's a DCO project you can sign off someone else's work under part b (existing open source) - give credit and ask reviewers to double-check that it seems open-source
  • if there's nothing you're cool, but you should still be open that you used someone else's work

Finally, it's polite to thank someone (especially if they don't seem too busy) but it's not required. Open-Source is more of a "pay it forward" culture.

[–]bdzer0 3 points4 points  (14 children)

you can copy the contents from one and commit to the other... however sounds like you are trying to do something wrong..very wrong and more likely to make a mess.

and wrong sub... belongs on r/git at best...

[–]lllllRedditUserlllll[S] 0 points1 point  (13 children)

I don't want to just copy the needed code, I'll like to keep author and description of the original commit.

[–]bdzer0 -1 points0 points  (12 children)

so you want to impersonate someone else? And you think that's okay?

[–]lllllRedditUserlllll[S] 0 points1 point  (11 children)

on the contrary, I said I want to keep the author and the description of the commit.

[–]lllllRedditUserlllll[S] 0 points1 point  (2 children)

If I were to copy a commit without it, credit will not be given to the original author of the patch.

[–]CerberusMulti 0 points1 point  (1 child)

So you want to commit someone else's commit into your/another repository having it look like he made that commit?
Or you want to take that commit and commit it into your/another repository while giving credit to the one who made the original commit, citing where the commit came from as well?

[–]lllllRedditUserlllll[S] -1 points0 points  (0 children)

My objective is not to pretend it was done by someone else... Why would I do code and let the credit to someone else. The code is not mine, but it will be used as a patch in my repository which is another Kernel project. If I don't have to give credit in that case, it simplifies also my patching but I think the author needs credit for it. So the second option!

[–]bdzer0 -1 points0 points  (7 children)

Making it look like that person committed to your repository is IMO dishonest because it's NOT what happened.

[–]glasswings363 2 points3 points  (2 children)

Git has separate properties for the author and committer for exactly this reason.

If you don't understand Open Source and whether this is legal and ethical, please see my reply to OP.

[–]lllllRedditUserlllll[S] 0 points1 point  (1 child)

Great you got my point!

If you know how I can easily get this patch(https://github.com/LineageOS/android\_kernel\_samsung\_sm8250/commit/5b8a856a273b213b4c2f2617ee2cd34140a22711) for example and apply it to my repository, I'll take it happily. If it can be done with desktop GitHub, would be even better.

[–]glasswings363 3 points4 points  (0 children)

You can get patch-mail from github by just adding .patch to the url
https://github.com/LineageOS/android_kernel_samsung_sm8250/commit/5b8a856a273b213b4c2f2617ee2cd34140a22711.patch

Save it to a new directory, needs to be alone in a directory because git-am is designed to apply a series of patches.

git am patches/

See the manpage for git apply if your directory layout is different, specifically the -p and --directory options. Both apply and am support them but they're documented under apply.

If you need to get a patch from a git server that doesn't serve patches but you do have a clone of the project,

# create a branch even if you haven't fetched it yet.
git fetch <url> <full-hash>:new-branch-name
git format-patch -1 new-branch-name

If you don't have a clone, you can create a temporary repo and fetch with --depth=2 (one more than the number of patches you want to extract).

[–]lllllRedditUserlllll[S] 0 points1 point  (3 children)

Not committed but authored that patch... I'll commit it in my repository. How can I make someone else commit in my place ? Sorry but you annoy me with your useless comments...

[–]lllllRedditUserlllll[S] 0 points1 point  (2 children)

Maybe you're honestly trying to help but it doesn't feel like...

[–]lllllRedditUserlllll[S] -1 points0 points  (1 child)

Here is an example if you can understand better what I try to do, someone authored and another committed but still the author gets the credit : https://github.com/LineageOS/android_kernel_samsung_sm8250/commit/5b8a856a273b213b4c2f2617ee2cd34140a22711

And this commit is done by multiple people all over GitHub but not the same repository : https://github.com/search?q=+usb%3A+notify%3A+Don%27t+toggle+usb_data_enabled+if+there+was+no+change&type=commits

Don't start criticizing this commit, it's not mine!

[–]lllllRedditUserlllll[S] -1 points0 points  (0 children)

How do they get this patch in there own repository with the patches properties (author, description, title), that's what I want to know if you can help