0

Say I have a Git history that looks like this, for newest to oldest:

* C: WIP: Latest change
* B: WIP: Older changer
* A: Groundwork/housekeeping - review ready
* (origin/master) Existing master commit
* ...

Commits B and C are work in progress, and I'm not ready to send for review yet, but I have some housekeeping/groundwork that I have split out into commit A and rebased in front of B and C. I am ready to send this for review.

I know I can create a new branch at commit A and review that, or reset/checkout, review and return, but is there a simple one liner with git-review that I can use to send just this one commit for review?

Inductiveload
  • 6,094
  • 4
  • 29
  • 55
  • I would like to suggest local branch as much as you can, so that you can avoid such cases. – love Jan 05 '16 at 12:06
  • @love, sure, I know how to do that (this is all on a topic branch anyway), just lazily trying to save branching, rebasing or checking out when the code to be reviewed is a simple ancestor. – Inductiveload Jan 05 '16 at 12:13

2 Answers2

0

You can create a new branch using git branch for whatever target commit you want. In your case, if you want to create a new branch pointing at A, you can do it like this:

git branch newbranch A

You can also use the checkout -b syntax to check it out immediately:

git checkout -b newbranch A

You can then submit that branch and its commit A for review. Once it’s merged in, you can rebase B and C so they base off the new origin/master.

poke
  • 369,085
  • 72
  • 557
  • 602
0

I think it is not possible with git-review, but you can do this without git-review using raw push command.

For example usually without git-review you will use command like this:

git push origin HEAD:refs/for/master

And if you want to push only one (it will be one only in case if all commits before A are already in master) specific commit, for example commit A, you can use its hash instead of HEAD:

git push origin A:refs/for/master

But usage of hash is not very nice because you should know it and you can do this in more easier way using construction like this HEAD~2, this will tell git use third commit starting from HEAD and in your case it will be A:

git push origin HEAD~2:refs/for/master

But construction like git push origin HEAD~2:refs/for/master is too long and instead of it you can create several git aliases like this (example aliases bellow will always use master as destination branch, so if in your workflow you are using several destination branches like master with development then you will need to create aliases for each branch like review-master-2 and review-development-2):

git config --global alias.review-1 'push origin HEAD~1:refs/for/master'
git config --global alias.review-2 'push origin HEAD~2:refs/for/master'
git config --global alias.review-3 'push origin HEAD~3:refs/for/master'
git config --global alias.review-4 'push origin HEAD~4:refs/for/master'
git config --global alias.review-5 'push origin HEAD~5:refs/for/master'

And with aliases you can push commit A using short command like this:

git review-2
Ivan M.
  • 164
  • 1
  • 1
  • 4