Skip to content

Instantly share code, notes, and snippets.

@philipstanislaus
Last active December 1, 2023 10:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipstanislaus/88cea550a29c332e39a120f8b2d904fd to your computer and use it in GitHub Desktop.
Save philipstanislaus/88cea550a29c332e39a120f8b2d904fd to your computer and use it in GitHub Desktop.
Create empty git base commit for a full code review
# create empty base commit that will be the reference for our code review
git checkout --orphan base
git rm -r --cached .
git clean -fxd
git commit --allow-empty -m "Start of the review"
# create and checkout review branch that will include the latest code that should be reviewed
git checkout -b review
# merge main branch into that new review branch
git merge main --allow-unrelated-histories --no-edit
# for a detailed explanation https://astrofrog.github.io/blog/2013/04/10/how-to-conduct-a-full-code-review-on-github/
@philipstanislaus
Copy link
Author

philipstanislaus commented Sep 13, 2021

Same as above as a one-liner

git checkout --orphan base && git rm -r --cached . && git clean -fxd && git commit --allow-empty -m "Start of the review" && git checkout -b review && git merge main --allow-unrelated-histories --no-edit

@philipstanislaus
Copy link
Author

philipstanislaus commented Dec 1, 2023

Use the following to create a new commits with updates to the codebase that should be reviewed. This ensures the updates are theirs only.

# create and checkout updates branch that will contain new updated code that should be reviewed
git checkout -b updates

# merge changes from branch with code that should be reviewed (assuming `main` here), but without conflicts, the contents of 'ours' will be discarded later
git merge -s ours main --no-edit

# make temporary branch to merged commit
git branch temp

# get contents of working tree and index to the one of main
git reset --hard main

# reset to our merged commit but keep contents of working tree and index
git reset --soft temp

# change the contents of the merged commit with the contents of main
git commit --amend --no-edit

# get rid of our temporary branch
git branch -D temp

# verify that the merge commit contains only contents of main
git diff HEAD main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment