How to add a commit ID to a series of cherry picks?

扶醉桌前 提交于 2019-12-12 05:30:45

问题


I'm trying to contribute to the LineageOS gerrit.

So essentially I cherry picked a range of commits from an upstream kernel branch...

Only now, none of the cherry picked commits have a Change-ID. I know I can manually add one with a commit hook and:

git commit --amend

However, there are 834 or so commits... I'm also aware that I could run an interactive rebase to slightly ease my pain via:

git rebase -i $FIRST_CP
# Change every commit from pick to edit
git commit --amend
git rebase --continue

However this is almost just as bad as cherry picking every single commit all over again.

Note: I do not have admin access to the Gerrit server so I cannot temporarily remove the requirement of change IDs.

I'm at my wits end and this is really putting a damper on my contributions... Hope someone has a better idea.

Addenum: I also tried merging the branch and hoping it would be accepted... No dice though.


回答1:


Try git filter-branch --msg-filter.

Let's say we have the hook to generate Change-Id at ~/commit-msg, and we are now on master.

#create an orphan branch "tmp" from "master".
git checkout --orphan tmp master
git commit -m 'new root'

#cherry-pick all the commits from an upstream kernel branch.
git cherry-pick <all-the-commits>

#rewrite the commit message of every commit on "tmp"
git filter-branch --msg-filter 'git log -1 --pretty=%B $GIT_COMMIT > msg.txt;~/commit-msg msg.txt;cat msg.txt'

#all the commits now have Change-Id
#cherry-pick all of them except the root to "master"
root=$(git log --pretty=%H --max-parents=0)
git checkout master
git cherry-pick $root..tmp

msg.txt is created in .git-rewrite/ under the current repository, and .git-rewrite/ is deleted automatically after the command is done. So let's just ignore it.

The msg-filter command simulates the process of generating Change-Id. I think it could be more elegant, but it works in my test.




回答2:


-n, --no-commit will let you cherry-pick one or more existing commits without any commit. After doing this, you can commit all those cherry-picked with one commit ID.



来源:https://stackoverflow.com/questions/45581427/how-to-add-a-commit-id-to-a-series-of-cherry-picks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!