- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
DeleteFileCommand
Deletes a specified file from a specified branch. A commit is created on the branch that contains the revision. The file still exists in the commits earlier to the commit that contains the deletion.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { CodeCommitClient, DeleteFileCommand } from "@aws-sdk/client-codecommit"; // ES Modules import
// const { CodeCommitClient, DeleteFileCommand } = require("@aws-sdk/client-codecommit"); // CommonJS import
const client = new CodeCommitClient(config);
const input = { // DeleteFileInput
repositoryName: "STRING_VALUE", // required
branchName: "STRING_VALUE", // required
filePath: "STRING_VALUE", // required
parentCommitId: "STRING_VALUE", // required
keepEmptyFolders: true || false,
commitMessage: "STRING_VALUE",
name: "STRING_VALUE",
email: "STRING_VALUE",
};
const command = new DeleteFileCommand(input);
const response = await client.send(command);
// { // DeleteFileOutput
// commitId: "STRING_VALUE", // required
// blobId: "STRING_VALUE", // required
// treeId: "STRING_VALUE", // required
// filePath: "STRING_VALUE", // required
// };
DeleteFileCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
branchName Required | string | undefined | The name of the branch where the commit that deletes the file is made. |
filePath Required | string | undefined | The fully qualified path to the file that to be deleted, including the full name and extension of that file. For example, /examples/file.md is a fully qualified path to a file named file.md in a folder named examples. |
parentCommitId Required | string | undefined | The ID of the commit that is the tip of the branch where you want to create the commit that deletes the file. This must be the HEAD commit for the branch. The commit that deletes the file is created from this commit ID. |
repositoryName Required | string | undefined | The name of the repository that contains the file to delete. |
commitMessage | string | undefined | The commit message you want to include as part of deleting the file. Commit messages are limited to 256 KB. If no message is specified, a default message is used. |
email | string | undefined | The email address for the commit that deletes the file. If no email address is specified, the email address is left blank. |
keepEmptyFolders | boolean | undefined | If a file is the only object in the folder or directory, specifies whether to delete the folder or directory that contains the file. By default, empty folders are deleted. This includes empty folders that are part of the directory structure. For example, if the path to a file is dir1/dir2/dir3/dir4, and dir2 and dir3 are empty, deleting the last file in dir4 also deletes the empty folders dir4, dir3, and dir2. |
name | string | undefined | The name of the author of the commit that deletes the file. If no name is specified, the user's ARN is used as the author name and committer name. |
DeleteFileCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
blobId Required | string | undefined | The blob ID removed from the tree as part of deleting the file. |
commitId Required | string | undefined | The full commit ID of the commit that contains the change that deletes the file. |
filePath Required | string | undefined | The fully qualified path to the file to be deleted, including the full name and extension of that file. |
treeId Required | string | undefined | The full SHA-1 pointer of the tree information for the commit that contains the delete file change. |
Throws
Name | Fault | Details |
---|
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. |
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. |
FileDoesNotExistException | client | The specified file does not exist. Verify that you have used the correct file name, full path, and extension. |
InvalidBranchNameException | client | The specified reference name 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. |
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. |
NameLengthExceededException | client | The user name is not valid because it has exceeded the character limit for author names. |
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. |
RepositoryDoesNotExistException | client | The specified repository does not exist. |
RepositoryNameRequiredException | client | A repository name is required, but was not specified. |
CodeCommitServiceException | Base exception class for all service exceptions from CodeCommit service. |