How can I do a branch review with gerrit? I want to analyse all branch changes in one gerrit change.
The idea is to review the code of a branch with multiple changes (commits).
How can I do a branch review with gerrit? I want to analyse all branch changes in one gerrit change.
The idea is to review the code of a branch with multiple changes (commits).
If you want to review a branch with multiple commits Gerrit isn't an appropriate tool for that. Reviews in Gerrit are performed in every commit individually. Github or Bitbucket are tools suitable for branch review.
Answered your question, a suggestion: IMHO you should try to work with Gerrit, reviewing every commit individually, because it's a very nice workflow. I really like (and prefer) Gerrit strategy.
I created a git alias which facilitates the traditional git workflow (with multiple commits on a "working" branch) along with pushing them to Gerrit automatically with the same Change-Id in the commit message. It can be added to .gitconfig file:
...
[alias]
gerrit = "!git reset --soft $(git rev-list master..HEAD | tail -1) && \
git commit --amend --no-edit && \
(git push origin HEAD:refs/for/master; git reset HEAD@{2})"
Assumption:
Usage: git gerrit
This works as follows:
git reset --soft $(git rev-list master..HEAD | tail -1)
git rev-list master..HEAD | tail -1
obtains SHA-1 of the first commit we created on the branch (after forking from master
), I will call it the "base" commit. Then we feed this SHA-1 to: git reset --soft
which moves the branch pointer back to this commit turning all changes from later commits into staged. Then:
git commit --amend --no-edit
we squash staged changes into the base commit with a single --amend
. The original commit message will be preserved and so will be Change-Id.
git push origin HEAD:refs/for/master
This is the point of everything - we push to Gerrit...
git reset HEAD@{2}
and finally we restore the original shape of our branch utilizing reflog history, HEAD@{2}
means a revision where our HEAD was two steps ago (before commit --amend
and first reset
).
Advantages:
git rebase -i
as much as you like for logical order and readability (don't modify Change-Id from the "base" commit message);© 2022 - 2024 — McMap. All rights reserved.