git town compress
git town compress [-m <text> | --message <text>] [-s | --stack] [--dry-run] [-v | --verbose]
The compress command squashes all commits on a branch into a single commit.
Assuming you have a feature branch with these commits:
$ git log --pretty=format:'%s'
commit 1
commit 2
commit 3
Let’s compress these three commits into a single commit:
git town compress
Now your branch has a single commit with the name of the first commit but containing the changes of all three commits that existed on the branch before:
$ git log --pretty=format:'%s'
commit 1
Git Town compresses feature branches and parked branches. It doesn’t compress perennial, observed, and contribution branches.
Branches must be in sync to compress them; run git town sync
before running
this command.
Options
-m <text>
--message <text>
By default the now compressed commit uses the commit message of the first commit
in the branch. You can provide a custom commit message for the squashed commit
with the --message <message>
aka -m
flag, which works similar to the
-m flag for git commit
.
Assuming you have a feature branch with these commits:
$ git log --pretty=format:'%s'
commit 1
commit 2
commit 3
Let’s compress these three commits into a single commit:
git town compress -m "compressed commit"
Now your branch has these commits:
$ git log --pretty=format:'%s'
compressed commit
The new compressed commit
now contains the changes from the old commit 1
,
commit 2
, and commit 3
.
-s
--stack
To compress all branches in a stack provide the
--stack
aka -s
switch.
If you want to compress your commits every time you sync, choose the compress sync strategy for the respective branch type.
Assuming you have a stacked change consisting of two feature branches. Each branch contains three commits.
main
\
branch-1
| * commit 1a
| * commit 1b
| * commit 1c
branch-2
* commit 2a
* commit 2b
* commit 2c
Let’s compress the commits in all branches of this stack:
git town compress --stack
Now your stack contains these branches and commits:
main
\
branch-1
| * commit 1a
branch-2
* commit 2a
As usual, the new commit 1a
contains the changes made in branch 1
, i.e. the
changes from the old commit 1a
, commit 1b
, and commit 1c
. The new
commit 2a
contains the changes made in branch 2
, i.e. the changes from the
old commit 2a
, commit 2b
, and commit 2c
.
--dry-run
Use the --dry-run
flag to test-drive this command. It prints the Git commands
that would be run but doesn’t execute them.
-v
--verbose
The --verbose
aka -v
flag prints all Git commands run under the hood to
determine the repository state.