Chih-Ying Lin Chih-Ying Lin - 1 year ago 155
Git Question

How to remove Change-Id from git commit by command

When I cherry-pick a patch from Gerrit and push it again to different branch on same server, the server reply error message:

Total 0 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done
To ssh://xxxxxx.git
! [remote rejected] HEAD -> refs/for/xxxx (no new changes)
error: failed to push some refs to 'ssh://xxxxxx.git'

git commit --amend
to remove
line can fix this problem.

I want to write a script to do it automatically. Is there any command/parameter to achieve same result?

Answer Source

You could use the --no-commit option; something like (you'll need to tweak this)

git cherry-pick --no-commit <sha-1>
COMMIT_MSG=$(git log -n 1 --pretty=format:%s%b <sha-1>)
# some bash operation to remove the Change-id from COMMIT_MSG variable
git commit -m "$COMMIT_MSG"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download