Stacked diffs
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
- Status: Experiment
Use stacked diffs in the GitLab CLI to create small changes that build upon each other to ultimately deliver a feature. Each stack is separate, so you can:
- Continue building new features while earlier changes are reviewed.
- Respond to review feedback on specific diffs without affecting other work.
- Merge diffs independently as they’re approved.
The workflow for stacked diffs is:
Create changes: When you run
glab stack save, the GitLab CLI:- Stages all your changes.
- Creates a new commit with your message.
- Creates a new branch for this commit.
- Moves you to the new branch automatically.
Sync to GitLab: When you run
glab stack sync, the GitLab CLI:- Pushes all branches in your stack to GitLab.
- Creates a merge request for each diff that doesn’t have one yet.
- Chains the merge requests together. Each merge request, except the first one, targets the previous diff branch.
The base command for this feature in the CLI is stack, which you then extend with other commands.
This feature is an experiment. We’d love to hear your feedback in issue 7473.
Create a stacked diff
Create a stacked diff when you want to break a large feature into smaller, reviewable changes.
Prerequisites:
- You must have the GitLab CLI installed and authenticated.
To create a stacked diff:
In your terminal, create a new stack and give it a name. For example:
glab stack create add-authenticationMake your first set of changes in your editor.
Save your changes as the first diff:
glab stack saveWhen prompted, enter a commit message that describes this change.
Make your next set of changes and save these as a second diff:
glab stack saveEach time you run
glab stack save, you create a new diff and branch. When prompted, enter a commit message that describes this change.When you’re ready to push your changes to GitLab and create merge requests, run:
glab stack sync
Your merge requests are available for review. You can continue creating more diffs in this stack, or switch to work on something else.
Add changes to a diff in a stack
To return to a specific point in the stack to add more changes to it:
Display a list of stacks:
glab stack moveSelect the stack you want to edit and press Enter.
Make your changes.
When you’re ready, save your changes, and run:
glab stack amendOptional. Change the description of the stack.
Push your changes:
glab stack sync
When you sync an existing stack, GitLab:
- Updates the existing stack with your new changes.
- Rebases the other merge requests in the stack to bring in your latest changes.
Available commands
Use these commands to work with stacked diffs:
| Command | Description |
|---|---|
create | Create a new stack. |
save | Save your changes as a new diff. |
amend | Modify the current diff. |
prev | Move to the previous diff. |
next | Move to the next diff. |
first | Move to the first diff. |
last | Move to the last diff. |
move | Select any diff from a list. |
sync | Push branches and create/update merge requests. |
Choose between save and amend
Use the following commands for different purposes:
glab stack save: Creates a new diff (commit and branch). Use this when you’re adding a new logical change to your stack.glab stack amend: Modifies the current diff. Use this when responding to review feedback or fixing the current change.