只接受git commit的一部分,推送到github

时间:2011-03-09 12:31:32

标签: git github rebase

我是github(Slippy)项目的粉丝。项目的另一个分支(by kageroh)有一个我想要推送到原始项目的提交,但维护者不想要整个提交,只是它的一部分。

我的理解是我可以使用交互式基础来仅承担部分提交,但我不应该因为它是已经在公共存储库上的提交。有没有办法参与提交,并将其拉到原始回购,作者的归属完整?或者我只需要复制我想要的更改并将它们放入我名下的新提交中?

2 个答案:

答案 0 :(得分:7)

我认为挑选并减少提交是可以的。要设置提交的作者,只需使用git commit --author="The Original Author <his@address>"

举一个例子,如果f414f3l是您要减少的提交,我可能会执行以下操作:

# 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>"

答案 1 :(得分:0)

重写公共分支的历史记录是一个坏主意,但对于单个提交没有什么神圣不可侵犯的意味着你无法复制它,修改它和将它发布在另一个分支上。

您可能只能基于上游主数据创建新分支,cherry-pick要修改的提交,然后commit --amend进行更改。这应该保留作者身份。

相关问题