AWS CodeCommit is no longer available to new customers. Existing customers of
AWS CodeCommit can continue to use the service as normal.
Learn more"
Compare and merge branches in AWS CodeCommit
You can use the CodeCommit console to compare branches in a CodeCommit repository. Comparing branches helps you quickly view the differences between a branch and the default branch, or view the differences between any two branches.
Topics
Compare a branch to the default branch
Use the CodeCommit console to quickly view the differences between a branch and the default branch for your repository.
Open the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home
. -
In Repositories, choose the name of the repository where you want to compare branches.
-
In the navigation pane, choose Commits, and then choose the Compare commits tab.
-
In Destination, choose the name of the default branch. In Source, choose the branch you want to compare to the default branch. Choose Compare.
Compare two specific branches
Use the CodeCommit console to view the differences between two branches that you want to compare.
Open the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home
. -
In Repositories, choose the name of the repository where you want to compare branches.
-
In the navigation pane, choose Commits, and then choose the Compare commits tab.
-
In Destination and Source, choose the two branches to compare, and then choose Compare. To view the list of changed files, expand the changed files list. You can view changes in files side by side (Split view) or inline (Unified view).
Note
If you are signed in as an IAM user, you can configure and save your preferences for viewing code and other console settings. For more information, see Working with user preferences.
Merge two branches (AWS CLI)
You can merge two branches in a CodeCommit repository using the AWS CLI using one of the available merge strategies by running one of the following commands:
-
To merge two branches using the fast-forward merge strategy, run the merge-branches-by-fast-forward command.
-
To merge two branches using the squash merge strategy, run the merge-branches-by-squash command.
-
To merge two branches using the three-way merge strategy, run the merge-branches-by-three-way command.
You can also test merges by running the create-unreferenced-merge-commit command. For more information, see Resolve Conflicts in a Pull Request.
Note
To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see Command line reference.
To use the AWS CLI to merge two branches in a CodeCommit repository
-
To merge two branches using the fast-forward merge strategy, run the merge-branches-by-fast-forward command, specifying:
-
The name of the source branch that contains the changes you want to merge (with the --source-commit-specifier option).
-
The name of the destination branch where you want to merge your changes (with the --destination-commit-specifier option).
-
The name of the repository (with the --repository-name option).
For example, to merge a source branch named
bugfix-1234
into a destination branch namedpreprod
in a repository namedMyDemoRepo
:aws codecommit merge-branches-by-fast-forward --source-commit-specifier
bugfix-bug1234
--destination-commit-specifierpreprod
--repository-nameMyDemoRepo
If successful, this command produces output similar to the following:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }
-
-
To merge two branches using the squash merge strategy, run the merge-branches-by-squash command, specifying:
-
The name of the source branch that contains the changes you want to merge (with the --source-commit-specifier option).
-
The name of the destination branch where you want to merge your changes (with the --destination-commit-specifier option).
-
The name of the repository (with the --repository-name option).
-
The commit message to include (with the --commit-message option).
-
The name to use for the commit (with the --name option).
-
The email address to use for the commit (with the --email option).
For example, to merge a source branch named
bugfix-bug1234
with a destination branch namedbugfix-quarterly
in a repository namedMyDemoRepo
:aws codecommit merge-branches-by-squash --source-commit-specifier
bugfix-bug1234
--destination-commit-specifierbugfix-quarterly
--author-name "Maria Garcia
" --email "maria_garcia@example.com
" --commit-message "Merging in fix branches to prepare for a general patch.
" --repository-nameMyDemoRepo
If successful, this command produces output similar to the following:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }
-
-
To merge two branches using the three-way merge strategy, run the merge-branches-by-three-way command, specifying:
-
The name of the source branch that contains the changes you want to merge (with the --source-commit-specifier option).
-
The name of the destination branch where you want to merge your changes (with the --destination-commit-specifier option).
-
The name of the repository (with the --repository-name option).
-
The commit message to include (with the --commit-message option).
-
The name to use for the commit (with the --name option).
-
The email address to use for the commit (with the --email option).
For example, to merge a source branch named
main
with a destination branch namedbugfix-1234
in a repository namedMyDemoRepo
:aws codecommit merge-branches-by-three-way --source-commit-specifier
main
--destination-commit-specifierbugfix-bug1234
--author-name "Jorge Souza
" --email "jorge_souza@example.com
" --commit-message "Merging changes from main to bugfix branch before additional testing.
" --repository-nameMyDemoRepo
If successful, this command produces output similar to the following:
{ "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }
-