Create a commit by streaming a Git patch instead of individual file blobs. Use this when your workflow already produces unified diffs or generated patches.
JWT claims
Required scopes: git:write
Requires per repo scope: Yes
Deprecated: Use /api/repos/{repo_name}/diff-commit instead.
POST
/
api
/
v1
/
repos
/
diff-commit
Diff Commit
curl --request POST \
--url https://api.{cluster}.code.storage/api/v1/repos/diff-commit \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/x-ndjson' \
--data '
"{\"metadata\":{\"target_branch\":\"main\",\"expected_head_sha\":\"d34db33fd34db33fd34db33fd34db33fd34db33f\",\"commit_message\":\"Apply generated patch\",\"author\":{\"name\":\"Diff Bot\",\"email\":\"diff@example.com\"}}}\n{\"diff_chunk\":{\"data\":\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\",\"eof\":false}}\n{\"diff_chunk\":{\"data\":\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\",\"eof\":true}}\n"
'import requests
url = "https://api.{cluster}.code.storage/api/v1/repos/diff-commit"
payload = "{\"metadata\":{\"target_branch\":\"main\",\"expected_head_sha\":\"d34db33fd34db33fd34db33fd34db33fd34db33f\",\"commit_message\":\"Apply generated patch\",\"author\":{\"name\":\"Diff Bot\",\"email\":\"diff@example.com\"}}}
{\"diff_chunk\":{\"data\":\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\",\"eof\":false}}
{\"diff_chunk\":{\"data\":\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\",\"eof\":true}}
"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/x-ndjson"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/x-ndjson'},
body: JSON.stringify('{"metadata":{"target_branch":"main","expected_head_sha":"d34db33fd34db33fd34db33fd34db33fd34db33f","commit_message":"Apply generated patch","author":{"name":"Diff Bot","email":"diff@example.com"}}}\n{"diff_chunk":{"data":"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=","eof":false}}\n{"diff_chunk":{"data":"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK","eof":true}}\n')
};
fetch('https://api.{cluster}.code.storage/api/v1/repos/diff-commit', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.{cluster}.code.storage/api/v1/repos/diff-commit",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode('{"metadata":{"target_branch":"main","expected_head_sha":"d34db33fd34db33fd34db33fd34db33fd34db33f","commit_message":"Apply generated patch","author":{"name":"Diff Bot","email":"diff@example.com"}}}
{"diff_chunk":{"data":"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=","eof":false}}
{"diff_chunk":{"data":"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK","eof":true}}
'),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/x-ndjson"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.{cluster}.code.storage/api/v1/repos/diff-commit"
payload := strings.NewReader("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"expected_head_sha\\\":\\\"d34db33fd34db33fd34db33fd34db33fd34db33f\\\",\\\"commit_message\\\":\\\"Apply generated patch\\\",\\\"author\\\":{\\\"name\\\":\\\"Diff Bot\\\",\\\"email\\\":\\\"diff@example.com\\\"}}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\\\",\\\"eof\\\":false}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\\\",\\\"eof\\\":true}}\\n\"")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/x-ndjson")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.{cluster}.code.storage/api/v1/repos/diff-commit")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/x-ndjson")
.body("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"expected_head_sha\\\":\\\"d34db33fd34db33fd34db33fd34db33fd34db33f\\\",\\\"commit_message\\\":\\\"Apply generated patch\\\",\\\"author\\\":{\\\"name\\\":\\\"Diff Bot\\\",\\\"email\\\":\\\"diff@example.com\\\"}}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\\\",\\\"eof\\\":false}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\\\",\\\"eof\\\":true}}\\n\"")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.{cluster}.code.storage/api/v1/repos/diff-commit")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/x-ndjson'
request.body = "\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"expected_head_sha\\\":\\\"d34db33fd34db33fd34db33fd34db33fd34db33f\\\",\\\"commit_message\\\":\\\"Apply generated patch\\\",\\\"author\\\":{\\\"name\\\":\\\"Diff Bot\\\",\\\"email\\\":\\\"diff@example.com\\\"}}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\\\",\\\"eof\\\":false}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\\\",\\\"eof\\\":true}}\\n\""
response = http.request(request)
puts response.read_body{
"commit": {
"blob_count": 1,
"commit_sha": "<string>",
"pack_bytes": 1,
"target_branch": "<string>",
"tree_sha": "<string>"
},
"result": {
"branch": "<string>",
"new_sha": "<string>",
"old_sha": "<string>",
"status": "<string>",
"success": true,
"message": "<string>"
}
}{
"result": {
"branch": "main",
"message": "diff payload could not be decoded",
"new_sha": "",
"old_sha": "",
"status": "invalid_diff",
"success": false
}
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"result": {
"branch": "main",
"message": "patch does not apply cleanly",
"new_sha": "",
"old_sha": "",
"status": "conflict",
"success": false
}
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/x-ndjson
Send newline-delimited JSON where the first line is a metadata object and each following line is a diff_chunk. The combined diff must be compatible with git apply --cached --binary.
NDJSON stream. The first line must be metadata; subsequent lines must be diff_chunk payloads. Decoded diff chunks are limited to 4 MiB each.
Response
Commit created from the supplied diff.
Previous
Reset Commits#### JWT claims
Required scopes: `git:write`
Requires per repo scope: Yes
Deprecated: Use `/api/repos/{repo_name}/reset-commits` instead.
Next
⌘I
Diff Commit
curl --request POST \
--url https://api.{cluster}.code.storage/api/v1/repos/diff-commit \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/x-ndjson' \
--data '
"{\"metadata\":{\"target_branch\":\"main\",\"expected_head_sha\":\"d34db33fd34db33fd34db33fd34db33fd34db33f\",\"commit_message\":\"Apply generated patch\",\"author\":{\"name\":\"Diff Bot\",\"email\":\"diff@example.com\"}}}\n{\"diff_chunk\":{\"data\":\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\",\"eof\":false}}\n{\"diff_chunk\":{\"data\":\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\",\"eof\":true}}\n"
'import requests
url = "https://api.{cluster}.code.storage/api/v1/repos/diff-commit"
payload = "{\"metadata\":{\"target_branch\":\"main\",\"expected_head_sha\":\"d34db33fd34db33fd34db33fd34db33fd34db33f\",\"commit_message\":\"Apply generated patch\",\"author\":{\"name\":\"Diff Bot\",\"email\":\"diff@example.com\"}}}
{\"diff_chunk\":{\"data\":\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\",\"eof\":false}}
{\"diff_chunk\":{\"data\":\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\",\"eof\":true}}
"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/x-ndjson"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/x-ndjson'},
body: JSON.stringify('{"metadata":{"target_branch":"main","expected_head_sha":"d34db33fd34db33fd34db33fd34db33fd34db33f","commit_message":"Apply generated patch","author":{"name":"Diff Bot","email":"diff@example.com"}}}\n{"diff_chunk":{"data":"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=","eof":false}}\n{"diff_chunk":{"data":"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK","eof":true}}\n')
};
fetch('https://api.{cluster}.code.storage/api/v1/repos/diff-commit', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.{cluster}.code.storage/api/v1/repos/diff-commit",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode('{"metadata":{"target_branch":"main","expected_head_sha":"d34db33fd34db33fd34db33fd34db33fd34db33f","commit_message":"Apply generated patch","author":{"name":"Diff Bot","email":"diff@example.com"}}}
{"diff_chunk":{"data":"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=","eof":false}}
{"diff_chunk":{"data":"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK","eof":true}}
'),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/x-ndjson"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.{cluster}.code.storage/api/v1/repos/diff-commit"
payload := strings.NewReader("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"expected_head_sha\\\":\\\"d34db33fd34db33fd34db33fd34db33fd34db33f\\\",\\\"commit_message\\\":\\\"Apply generated patch\\\",\\\"author\\\":{\\\"name\\\":\\\"Diff Bot\\\",\\\"email\\\":\\\"diff@example.com\\\"}}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\\\",\\\"eof\\\":false}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\\\",\\\"eof\\\":true}}\\n\"")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/x-ndjson")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.{cluster}.code.storage/api/v1/repos/diff-commit")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/x-ndjson")
.body("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"expected_head_sha\\\":\\\"d34db33fd34db33fd34db33fd34db33fd34db33f\\\",\\\"commit_message\\\":\\\"Apply generated patch\\\",\\\"author\\\":{\\\"name\\\":\\\"Diff Bot\\\",\\\"email\\\":\\\"diff@example.com\\\"}}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\\\",\\\"eof\\\":false}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\\\",\\\"eof\\\":true}}\\n\"")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.{cluster}.code.storage/api/v1/repos/diff-commit")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/x-ndjson'
request.body = "\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"expected_head_sha\\\":\\\"d34db33fd34db33fd34db33fd34db33fd34db33f\\\",\\\"commit_message\\\":\\\"Apply generated patch\\\",\\\"author\\\":{\\\"name\\\":\\\"Diff Bot\\\",\\\"email\\\":\\\"diff@example.com\\\"}}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=\\\",\\\"eof\\\":false}}\\n{\\\"diff_chunk\\\":{\\\"data\\\":\\\"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK\\\",\\\"eof\\\":true}}\\n\""
response = http.request(request)
puts response.read_body{
"commit": {
"blob_count": 1,
"commit_sha": "<string>",
"pack_bytes": 1,
"target_branch": "<string>",
"tree_sha": "<string>"
},
"result": {
"branch": "<string>",
"new_sha": "<string>",
"old_sha": "<string>",
"status": "<string>",
"success": true,
"message": "<string>"
}
}{
"result": {
"branch": "main",
"message": "diff payload could not be decoded",
"new_sha": "",
"old_sha": "",
"status": "invalid_diff",
"success": false
}
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"result": {
"branch": "main",
"message": "patch does not apply cleanly",
"new_sha": "",
"old_sha": "",
"status": "conflict",
"success": false
}
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}