CreateCommitCommand

Creates a commit for a repository on the tip of a specified branch.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { CodeCommitClient, CreateCommitCommand } from "@aws-sdk/client-codecommit"; // ES Modules import
// const { CodeCommitClient, CreateCommitCommand } = require("@aws-sdk/client-codecommit"); // CommonJS import
const client = new CodeCommitClient(config);
const input = { // CreateCommitInput
  repositoryName: "STRING_VALUE", // required
  branchName: "STRING_VALUE", // required
  parentCommitId: "STRING_VALUE",
  authorName: "STRING_VALUE",
  email: "STRING_VALUE",
  commitMessage: "STRING_VALUE",
  keepEmptyFolders: true || false,
  putFiles: [ // PutFileEntries
    { // PutFileEntry
      filePath: "STRING_VALUE", // required
      fileMode: "EXECUTABLE" || "NORMAL" || "SYMLINK",
      fileContent: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
      sourceFile: { // SourceFileSpecifier
        filePath: "STRING_VALUE", // required
        isMove: true || false,
      },
    },
  ],
  deleteFiles: [ // DeleteFileEntries
    { // DeleteFileEntry
      filePath: "STRING_VALUE", // required
    },
  ],
  setFileModes: [ // SetFileModeEntries
    { // SetFileModeEntry
      filePath: "STRING_VALUE", // required
      fileMode: "EXECUTABLE" || "NORMAL" || "SYMLINK", // required
    },
  ],
};
const command = new CreateCommitCommand(input);
const response = await client.send(command);
// { // CreateCommitOutput
//   commitId: "STRING_VALUE",
//   treeId: "STRING_VALUE",
//   filesAdded: [ // FilesMetadata
//     { // FileMetadata
//       absolutePath: "STRING_VALUE",
//       blobId: "STRING_VALUE",
//       fileMode: "EXECUTABLE" || "NORMAL" || "SYMLINK",
//     },
//   ],
//   filesUpdated: [
//     {
//       absolutePath: "STRING_VALUE",
//       blobId: "STRING_VALUE",
//       fileMode: "EXECUTABLE" || "NORMAL" || "SYMLINK",
//     },
//   ],
//   filesDeleted: [
//     {
//       absolutePath: "STRING_VALUE",
//       blobId: "STRING_VALUE",
//       fileMode: "EXECUTABLE" || "NORMAL" || "SYMLINK",
//     },
//   ],
// };

CreateCommitCommand Input

See CreateCommitCommandInput for more details

Parameter
Type
Description
branchName
Required
string | undefined

The name of the branch where you create the commit.

repositoryName
Required
string | undefined

The name of the repository where you create the commit.

authorName
string | undefined

The name of the author who created the commit. This information is used as both the author and committer for the commit.

commitMessage
string | undefined

The commit message you want to include in the commit. Commit messages are limited to 256 KB. If no message is specified, a default message is used.

deleteFiles
DeleteFileEntry[] | undefined

The files to delete in this commit. These files still exist in earlier commits.

email
string | undefined

The email address of the person who created the commit.

keepEmptyFolders
boolean | undefined

If the commit contains deletions, whether to keep a folder or folder structure if the changes leave the folders empty. If true, a ..gitkeep file is created for empty folders. The default is false.

parentCommitId
string | undefined

The ID of the commit that is the parent of the commit you create. Not required if this is an empty repository.

putFiles
PutFileEntry[] | undefined

The files to add or update in this commit.

setFileModes
SetFileModeEntry[] | undefined

The file modes to update for files in this commit.

CreateCommitCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
commitId
string | undefined

The full commit ID of the commit that contains your committed file changes.

filesAdded
FileMetadata[] | undefined

The files added as part of the committed file changes.

filesDeleted
FileMetadata[] | undefined

The files deleted as part of the committed file changes.

filesUpdated
FileMetadata[] | undefined

The files updated as part of the commited file changes.

treeId
string | undefined

The full SHA-1 pointer of the tree information for the commit that contains the commited file changes.

Throws

Name
Fault
Details
BranchDoesNotExistException
client

The specified branch does not exist.

BranchNameIsTagNameException
client

The specified branch name is not valid because it is a tag name. Enter the name of a branch in the repository. For a list of valid branch names, use ListBranches.

BranchNameRequiredException
client

A branch name is required, but was not specified.

CommitMessageLengthExceededException
client

The commit message is too long. Provide a shorter string.

DirectoryNameConflictsWithFileNameException
client

A file cannot be added to the repository because the specified path name has the same name as a file that already exists in this repository. Either provide a different name for the file, or specify a different path for the file.

EncryptionIntegrityChecksFailedException
server

An encryption integrity check failed.

EncryptionKeyAccessDeniedException
client

An encryption key could not be accessed.

EncryptionKeyDisabledException
client

The encryption key is disabled.

EncryptionKeyNotFoundException
client

No encryption key was found.

EncryptionKeyUnavailableException
client

The encryption key is not available.

FileContentAndSourceFileSpecifiedException
client

The commit cannot be created because both a source file and file content have been specified for the same file. You cannot provide both. Either specify a source file or provide the file content directly.

FileContentSizeLimitExceededException
client

The file cannot be added because it is too large. The maximum file size is 6 MB, and the combined file content change size is 7 MB. Consider making these changes using a Git client.

FileDoesNotExistException
client

The specified file does not exist. Verify that you have used the correct file name, full path, and extension.

FileEntryRequiredException
client

The commit cannot be created because no files have been specified as added, updated, or changed (PutFile or DeleteFile) for the commit.

FileModeRequiredException
client

The commit cannot be created because no file mode has been specified. A file mode is required to update mode permissions for a file.

FileNameConflictsWithDirectoryNameException
client

A file cannot be added to the repository because the specified file name has the same name as a directory in this repository. Either provide another name for the file, or add the file in a directory that does not match the file name.

FilePathConflictsWithSubmodulePathException
client

The commit cannot be created because a specified file path points to a submodule. Verify that the destination files have valid file paths that do not point to a submodule.

FolderContentSizeLimitExceededException
client

The commit cannot be created because at least one of the overall changes in the commit results in a folder whose contents exceed the limit of 6 MB. Either reduce the number and size of your changes, or split the changes across multiple folders.

InvalidBranchNameException
client

The specified reference name is not valid.

InvalidDeletionParameterException
client

The specified deletion parameter is not valid.

InvalidEmailException
client

The specified email address either contains one or more characters that are not allowed, or it exceeds the maximum number of characters allowed for an email address.

InvalidFileModeException
client

The specified file mode permission is not valid. For a list of valid file mode permissions, see PutFile.

InvalidParentCommitIdException
client

The parent commit ID is not valid. The commit ID cannot be empty, and must match the head commit ID for the branch of the repository where you want to add or update a file.

InvalidPathException
client

The specified path is not valid.

InvalidRepositoryNameException
client

A specified repository name is not valid.

This exception occurs only when a specified repository name is not valid. Other exceptions occur when a required repository parameter is missing, or when a specified repository does not exist.

MaximumFileEntriesExceededException
client

The number of specified files to change as part of this commit exceeds the maximum number of files that can be changed in a single commit. Consider using a Git client for these changes.

NameLengthExceededException
client

The user name is not valid because it has exceeded the character limit for author names.

NoChangeException
client

The commit cannot be created because no changes will be made to the repository as a result of this commit. A commit must contain at least one change.

ParentCommitDoesNotExistException
client

The parent commit ID is not valid because it does not exist. The specified parent commit ID does not exist in the specified branch of the repository.

ParentCommitIdOutdatedException
client

The file could not be added because the provided parent commit ID is not the current tip of the specified branch. To view the full commit ID of the current head of the branch, use GetBranch.

ParentCommitIdRequiredException
client

A parent commit ID is required. To view the full commit ID of a branch in a repository, use GetBranch or a Git command (for example, git pull or git log).

PathRequiredException
client

The folderPath for a location cannot be null.

PutFileEntryConflictException
client

The commit cannot be created because one or more files specified in the commit reference both a file and a folder.

RepositoryDoesNotExistException
client

The specified repository does not exist.

RepositoryNameRequiredException
client

A repository name is required, but was not specified.

RestrictedSourceFileException
client

The commit cannot be created because one of the changes specifies copying or moving a .gitkeep file.

SamePathRequestException
client

The commit cannot be created because one or more changes in this commit duplicate actions in the same file path. For example, you cannot make the same delete request to the same file in the same file path twice, or make a delete request and a move request to the same file as part of the same commit.

SourceFileOrContentRequiredException
client

The commit cannot be created because no source files or file content have been specified for the commit.

CodeCommitServiceException
Base exception class for all service exceptions from CodeCommit service.