Add Commits in the Stack

You can create stacked PRs with Aviator CLI and send them for review. Your reviewer might request some code changes in one of the PRs in the middle of the stack. This how-to guide explains how to add a change in such cases.

Setup

Let's use Hello-World repository as an example.

$ git clone https://github.com/octocat/hello-world hello-world
$ cd hello-world
$ av init
$ touch myfile
$ git add myfile

Then, create one branch.

$ av stack branch stack-1
$ echo 1a >> myfile
$ git commit -m 1a myfile
$ echo 1b >> myfile
$ git commit -m 1b myfile
$ av stack branch stack-2
$ echo 2a >> myfile
$ git commit -m 2a myfile
$ echo 2b >> myfile
$ git commit -m 2b myfile

This creates 2 branches.

Changing the stack-1

We have two branches that correspond to two PRs; stack-1 and stack-2. Let's assume that we need to change the stack-1. By running av stack prev, you can move back to the previous branch.

$ av stack prev
Checked out branch stack-1

You can switch the branch with git switch or git checkout as well.

Now make a necessary change.

$ echo 1c >> myfile
$ git commit -m 1c myfile

Currently the commit graph is like this:

We want to make stack-2 to be on top of the new commit 1c. To do this, run av stack sync.

$ av stack sync

  ✓ GitHub fetch is done
  ⣽ Restacking stack-2...

    * ⣽ stack-2 bca00e0

    * ✓ stack-1 88e3595

    * master 7fd1a60

  Rebase conflict while rebasing  stack-2
  Failed to rebase "refs/heads/stack-2" onto "refs/heads/stack-1" (merge base is "dd85e55")
  could not apply 8bf865c... 2a
  error: could not apply 8bf865c... 2a
  Recorded preimage for 'myfile'
  Could not apply 8bf865c... 2a


  Resolve the conflicts and continue the restack with av stack sync --continue

The file has a rebase conflict. Open myfile and resolve the conflict, and continue.

$ vim myfile
... Resolving conflict ...
$ git add .
$ av stack sync --continue

  ✓ Restack is done

    * ✓ stack-2 0be8a6e

    * ✓ stack-1 88e3595

    * master 7fd1a60

  ✓ Nothing to push to GitHub

    Following branches do not need a push.

      stack-1: No remote branch yet.
      stack-2: No remote branch yet.

  ✓ No merged branches to delete

Now the stack-2 is rebased on top of the new commit 1c.

Convenient CLI commands

When you need to change the commit in the middle of the stack, you almost always need to run av stack sync to align the child branches. Aviator CLI has convenient commands, av commit create and av commit amend that runs git commit along with av stack sync afterwards.

Last updated