简体   繁体   中英

Commit a file to git repository using Stash (bitbucket server) REST API

I am using Atlassian Stash (Bitbucket server) to manage my git repository. Recently I had a requirement to commit a file (a newly created .xml file) to my Git repository using the Stash REST API . I've gone through the documentation, but it seems like the REST API doesn't support that functionality.

Am I correct, or is this possible somehow?

This cannot be done via the Stash/Bitbucket Server REST API. I had to move to JGit , which is a Java wrapper for communication between GIT and Application.

The question Is it possible to commit a file to a remote base repository using JGit has more information.

Probably you are looking for

PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}

From the documentation of API

PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}

Update the content of path, on the given repository and branch. This resource accepts PUT multipart form data, containing the file in a form-field named content. An example curl request to update 'README.md' would be:

curl -X PUT -u username:password -F content=@README.md -F 'message=Updated using file-edit REST API' -F branch=master -F sourceCommitId=5636641a50b http://example.com/rest/api/latest/projects/PROJECT_1/repos/repo_1/browse/README.md

  • branch: the branch on which the path should be modified or created
  • content: the full content of the file at path message: the message associated with this change, to be used as the commit message. Or null if the default message should be used.
  • sourceCommitId: the commit ID of the file before it was edited, used to identify if content has changed. Or null if this is a new file.

The file can be updated or created on a new branch. In this case, the sourceBranch parameter should be provided to identify the starting point for the new branch and the branch parameter identifies the branch to create the new commit on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM