DeleteFile
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.
Request Syntax
{
"branchName": "string
",
"commitMessage": "string
",
"email": "string
",
"filePath": "string
",
"keepEmptyFolders": boolean
,
"name": "string
",
"parentCommitId": "string
",
"repositoryName": "string
"
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
- branchName
-
The name of the branch where the commit that deletes the file is made.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 256.
Required: Yes
- commitMessage
-
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.
Type: String
Required: No
-
The email address for the commit that deletes the file. If no email address is specified, the email address is left blank.
Type: String
Required: No
- filePath
-
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.
Type: String
Required: Yes
- keepEmptyFolders
-
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.
Type: Boolean
Required: No
- name
-
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.
Type: String
Required: No
- parentCommitId
-
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.
Type: String
Required: Yes
- repositoryName
-
The name of the repository that contains the file to delete.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 100.
Pattern:
[\w\.-]+
Required: Yes
Response Syntax
{
"blobId": "string",
"commitId": "string",
"filePath": "string",
"treeId": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- blobId
-
The blob ID removed from the tree as part of deleting the file.
Type: String
- commitId
-
The full commit ID of the commit that contains the change that deletes the file.
Type: String
- filePath
-
The fully qualified path to the file to be deleted, including the full name and extension of that file.
Type: String
- treeId
-
The full SHA-1 pointer of the tree information for the commit that contains the delete file change.
Type: String
Errors
For information about the errors that are common to all actions, see Common Errors.
- BranchDoesNotExistException
-
The specified branch does not exist.
HTTP Status Code: 400
- BranchNameIsTagNameException
-
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.
HTTP Status Code: 400
- BranchNameRequiredException
-
A branch name is required, but was not specified.
HTTP Status Code: 400
- CommitMessageLengthExceededException
-
The commit message is too long. Provide a shorter string.
HTTP Status Code: 400
- EncryptionIntegrityChecksFailedException
-
An encryption integrity check failed.
HTTP Status Code: 500
- EncryptionKeyAccessDeniedException
-
An encryption key could not be accessed.
HTTP Status Code: 400
- EncryptionKeyDisabledException
-
The encryption key is disabled.
HTTP Status Code: 400
- EncryptionKeyNotFoundException
-
No encryption key was found.
HTTP Status Code: 400
- EncryptionKeyUnavailableException
-
The encryption key is not available.
HTTP Status Code: 400
- FileDoesNotExistException
-
The specified file does not exist. Verify that you have used the correct file name, full path, and extension.
HTTP Status Code: 400
- InvalidBranchNameException
-
The specified reference name is not valid.
HTTP Status Code: 400
- InvalidEmailException
-
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.
HTTP Status Code: 400
- InvalidParentCommitIdException
-
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.
HTTP Status Code: 400
- InvalidPathException
-
The specified path is not valid.
HTTP Status Code: 400
- InvalidRepositoryNameException
-
A specified repository name is not valid.
Note
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.
HTTP Status Code: 400
- NameLengthExceededException
-
The user name is not valid because it has exceeded the character limit for author names.
HTTP Status Code: 400
- ParentCommitDoesNotExistException
-
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.
HTTP Status Code: 400
- ParentCommitIdOutdatedException
-
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.
HTTP Status Code: 400
- ParentCommitIdRequiredException
-
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).
HTTP Status Code: 400
- PathRequiredException
-
The folderPath for a location cannot be null.
HTTP Status Code: 400
- RepositoryDoesNotExistException
-
The specified repository does not exist.
HTTP Status Code: 400
- RepositoryNameRequiredException
-
A repository name is required, but was not specified.
HTTP Status Code: 400
Examples
Example
This example illustrates one usage of DeleteFile.
Sample Request
POST / HTTP/1.1
Host: codecommit.us-east-1.amazonaws.com
Accept-Encoding: identity
Content-Length: 182
X-Amz-Target: CodeCommit_20150413.DeleteFile
X-Amz-Date: 20180914T223454Z
User-Agent: aws-cli/1.15.9 Python/2.7.11 Darwin/16.7.0 botocore/1.10.9
Content-Type: application/x-amz-json-1.1
Authorization: AWS4-HMAC-SHA256 Credential=AKIAEXAMPLE/20180914/us-east-1/codecommit/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=0be88b13EXAMPLE
{
"branchName": "main",
"repositoryName": "MyDemoRepo",
"parentCommitId": "c5709475EXAMPLE",
"filePath": "README.md"
}
Sample Response
HTTP/1.1 200 OK
x-amzn-RequestId: 66c7bf89-EXAMPLE
Content-Type: application/x-amz-json-1.1
Content-Length: 182
Date: Fri, 14 Sep 2018 22:34:56 GMT
Connection: keep-alive
{
"blobId":"559b44fEXAMPLE",
"commitId":"353cf655EXAMPLE",
"filePath":"README.md",
"treeId":"6bc824cEXAMPLE"
}
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: