开发者

Take only part of a git commit, push to github

I'm a fan of a project on github (Slippy). Another fork of the project (by kageroh) has a commit that I want to push to the original project, but the maintainer doesn't want the whole commit, only part of it.

My understanding is that I could use 开发者_如何学编程interactive rebasing to take only part of the commit, but that I shouldn't because it's a commit that is already on a public repository. Is there a way to take part of the commit, and get it pulled to the original repo with the author's attribution intact? Or do I just have to copy the changes I want and put them into a new commit under my name?


I think it's fine to cherry-pick and reduce that commit. To set the author of the commit, just use git commit --author="The Original Author <his@address>".

To give an example, if f414f3l is the commit that you want to reduce, I would probably do the following:

# Make sure you're on the branch you want to create the new commit on:
git checkout master

# Now cherry-pick the commit, but only stage the changes:
git cherry-pick -n f414f3l

# Choose which hunks you want to unstage interactively, using the 's'
# option to split them where necessary.  (Or using the 'e' option for
# complete control over what patch to unstage.)
git reset -p

# When you commit, the commit message should be preserved:
git commit --author="The Original Author <his@address>"


Rewriting the history of a public branch is a bad idea, but there is nothing sacrosanct about an individual commit that means you can't copy it, modify it and publish it on another branch.

You may just be able to create a new branch based off the upstream master, cherry-pick the commit you want to modify and then commit --amend to change it. That should preserve authorship.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜