Compare and merge branches in AWS CodeCommit - AWS CodeCommit

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.

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.

  1. Open the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home.

  2. In Repositories, choose the name of the repository where you want to compare branches.

  3. In the navigation pane, choose Commits, and then choose the Compare commits tab.

  4. 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.

  1. Open the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home.

  2. In Repositories, choose the name of the repository where you want to compare branches.

  3. In the navigation pane, choose Commits, and then choose the Compare commits tab.

  4. 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.

    
                        An abbreviated view of the differences between two branches.

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:

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
  1. 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 named preprod in a repository named MyDemoRepo:

    aws codecommit merge-branches-by-fast-forward --source-commit-specifier bugfix-bug1234 --destination-commit-specifier preprod --repository-name MyDemoRepo

    If successful, this command produces output similar to the following:

    { "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }
  2. 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 named bugfix-quarterly in a repository named MyDemoRepo:

    aws codecommit merge-branches-by-squash --source-commit-specifier bugfix-bug1234 --destination-commit-specifier bugfix-quarterly --author-name "Maria Garcia" --email "maria_garcia@example.com" --commit-message "Merging in fix branches to prepare for a general patch." --repository-name MyDemoRepo

    If successful, this command produces output similar to the following:

    { "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }
  3. 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 named bugfix-1234 in a repository named MyDemoRepo:

    aws codecommit merge-branches-by-three-way --source-commit-specifier main --destination-commit-specifier bugfix-bug1234 --author-name "Jorge Souza" --email "jorge_souza@example.com" --commit-message "Merging changes from main to bugfix branch before additional testing." --repository-name MyDemoRepo

    If successful, this command produces output similar to the following:

    { "commitId": "4f178133EXAMPLE", "treeId": "389765daEXAMPLE" }