Add Change-Id to all commits

I just installed Gerrit and I wanted to push it, but I get an error message Change-Id, but it seems to be in the message that it complains.

$ git push gerrit HEAD:refs/publish/my-branch
Counting objects: 28, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (15/15), 4.46 KiB, done.
Total 15 (delta 12), reused 0 (delta 0)
remote: Resolving deltas: 100% (12/12)
remote: Processing changes: refs: 1, done    
remote: ERROR: missing Change-Id in commit message footer
remote: Suggestion for commit message:
remote: Revert "Refactoring controllers"
remote: 
remote: This reverts commit dd1c5c86b12461f61326fd102a11d9e3cb51142e.
remote: 
remote: Change-Id: Iaacf80a9e4f56b58d0b648112c3eb2413988f00e
remote: 
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@ci:hooks/commit-msg ${gitdir}/hooks/
remote: 
remote: 
To ssh://user@ci:29418/Project
! [remote rejected] HEAD -> refs/publish/my-branch (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://user@ci:29418/Project'

I guess this is because of previous commits that don't have Change-Id, because they were made before they were connected to the hook. How to update all previous commits to add Change-Id?

+4
source share
3 answers

In Gerrit - on the project settings page, disable the option that requires an identifier change at the time of commit. Then click on the existing commits on Gerrit.

+2
source

,

git checkout branchName
git rebase -i branchName

change pick to edit, , . git "" , edit. git commit --amend, ( , hook hrom gerrit, , ), git rebase --continue. change-id.
Rince , .

+1

. git filter-branch --msg-filter

Essentially, you want to create a new lost branch (without a previous history), and then rewrite all commits to have change identifiers.

You need a specific code example (literally from the previously mentioned answer)

#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
0
source

Source: https://habr.com/ru/post/1541115/


All Articles