doc/user/project/merge_requests/stacked_diffs.md
{{< details >}}
{{< /details >}}
{{< history >}}
{{< /history >}}
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:
The workflow for stacked diffs is:
Create changes: When you run glab stack save, the GitLab CLI:
Sync to GitLab: When you run glab stack sync, the GitLab CLI:
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 when you want to break a large feature into smaller, reviewable changes.
Prerequisites:
To create a stacked diff:
In your terminal, create a new stack and give it a name. For example:
glab stack create add-authentication
Make your first set of changes in your editor.
Save your changes as the first diff:
glab stack save
When prompted, enter a commit message that describes this change.
Make your next set of changes and save these as a second diff:
glab stack save
Each 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.
To return to a specific point in the stack to add more changes to it:
Display a list of stacks:
glab stack move
Select the stack you want to edit and press <kbd>Enter</kbd>.
Make your changes.
When you're ready, save your changes, and run:
glab stack amend
Optional. Change the description of the stack.
Push your changes:
glab stack sync
When you sync an existing stack, GitLab:
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. |
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.