Create a new commit that resets a branch back to a specific commit SHA while preserving normal Git history.
JWT claims
Required scopes: git:write
Requires per repo scope: Yes
Deprecated: Use /api/repos/{repo_name}/restore-commit instead.
POST
/
api
/
v1
/
repos
/
restore-commit
Restore Commit
curl --request POST \
--url https://api.{cluster}.code.storage/api/v1/repos/restore-commit \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/x-ndjson' \
--data '
"{\"metadata\":{\"target_branch\":\"main\",\"target_commit_sha\":\"abc123def4567890abc123def4567890abc123de\",\"expected_head_sha\":\"0123456789abcdef0123456789abcdef01234567\",\"commit_message\":\"Reset branch\",\"author\":{\"name\":\"Docs Bot\",\"email\":\"docs@example.com\"}}}\n"
'import requests
url = "https://api.{cluster}.code.storage/api/v1/repos/restore-commit"
payload = "{\"metadata\":{\"target_branch\":\"main\",\"target_commit_sha\":\"abc123def4567890abc123def4567890abc123de\",\"expected_head_sha\":\"0123456789abcdef0123456789abcdef01234567\",\"commit_message\":\"Reset branch\",\"author\":{\"name\":\"Docs Bot\",\"email\":\"docs@example.com\"}}}
"
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","target_commit_sha":"abc123def4567890abc123def4567890abc123de","expected_head_sha":"0123456789abcdef0123456789abcdef01234567","commit_message":"Reset branch","author":{"name":"Docs Bot","email":"docs@example.com"}}}\n')
};
fetch('https://api.{cluster}.code.storage/api/v1/repos/restore-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/restore-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","target_commit_sha":"abc123def4567890abc123def4567890abc123de","expected_head_sha":"0123456789abcdef0123456789abcdef01234567","commit_message":"Reset branch","author":{"name":"Docs Bot","email":"docs@example.com"}}}
'),
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/restore-commit"
payload := strings.NewReader("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"target_commit_sha\\\":\\\"abc123def4567890abc123def4567890abc123de\\\",\\\"expected_head_sha\\\":\\\"0123456789abcdef0123456789abcdef01234567\\\",\\\"commit_message\\\":\\\"Reset branch\\\",\\\"author\\\":{\\\"name\\\":\\\"Docs Bot\\\",\\\"email\\\":\\\"docs@example.com\\\"}}}\\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/restore-commit")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/x-ndjson")
.body("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"target_commit_sha\\\":\\\"abc123def4567890abc123def4567890abc123de\\\",\\\"expected_head_sha\\\":\\\"0123456789abcdef0123456789abcdef01234567\\\",\\\"commit_message\\\":\\\"Reset branch\\\",\\\"author\\\":{\\\"name\\\":\\\"Docs Bot\\\",\\\"email\\\":\\\"docs@example.com\\\"}}}\\n\"")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.{cluster}.code.storage/api/v1/repos/restore-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\\\",\\\"target_commit_sha\\\":\\\"abc123def4567890abc123def4567890abc123de\\\",\\\"expected_head_sha\\\":\\\"0123456789abcdef0123456789abcdef01234567\\\",\\\"commit_message\\\":\\\"Reset branch\\\",\\\"author\\\":{\\\"name\\\":\\\"Docs Bot\\\",\\\"email\\\":\\\"docs@example.com\\\"}}}\\n\""
response = http.request(request)
puts response.read_body{
"commit": {
"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>"
}
}{
"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>"
}{
"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>"
}{
"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 a single NDJSON metadata line describing the branch to restore and the commit SHA to restore it to.
NDJSON stream containing one metadata object.
Previous
Get NoteRead the Git note attached to a commit or other Git object SHA. Notes let you store review status, handoff details, or other context without changing repository contents.
#### JWT claims
Required scopes: `git:read`
Requires per repo scope: Yes
Next
⌘I
Restore Commit
curl --request POST \
--url https://api.{cluster}.code.storage/api/v1/repos/restore-commit \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/x-ndjson' \
--data '
"{\"metadata\":{\"target_branch\":\"main\",\"target_commit_sha\":\"abc123def4567890abc123def4567890abc123de\",\"expected_head_sha\":\"0123456789abcdef0123456789abcdef01234567\",\"commit_message\":\"Reset branch\",\"author\":{\"name\":\"Docs Bot\",\"email\":\"docs@example.com\"}}}\n"
'import requests
url = "https://api.{cluster}.code.storage/api/v1/repos/restore-commit"
payload = "{\"metadata\":{\"target_branch\":\"main\",\"target_commit_sha\":\"abc123def4567890abc123def4567890abc123de\",\"expected_head_sha\":\"0123456789abcdef0123456789abcdef01234567\",\"commit_message\":\"Reset branch\",\"author\":{\"name\":\"Docs Bot\",\"email\":\"docs@example.com\"}}}
"
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","target_commit_sha":"abc123def4567890abc123def4567890abc123de","expected_head_sha":"0123456789abcdef0123456789abcdef01234567","commit_message":"Reset branch","author":{"name":"Docs Bot","email":"docs@example.com"}}}\n')
};
fetch('https://api.{cluster}.code.storage/api/v1/repos/restore-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/restore-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","target_commit_sha":"abc123def4567890abc123def4567890abc123de","expected_head_sha":"0123456789abcdef0123456789abcdef01234567","commit_message":"Reset branch","author":{"name":"Docs Bot","email":"docs@example.com"}}}
'),
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/restore-commit"
payload := strings.NewReader("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"target_commit_sha\\\":\\\"abc123def4567890abc123def4567890abc123de\\\",\\\"expected_head_sha\\\":\\\"0123456789abcdef0123456789abcdef01234567\\\",\\\"commit_message\\\":\\\"Reset branch\\\",\\\"author\\\":{\\\"name\\\":\\\"Docs Bot\\\",\\\"email\\\":\\\"docs@example.com\\\"}}}\\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/restore-commit")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/x-ndjson")
.body("\"{\\\"metadata\\\":{\\\"target_branch\\\":\\\"main\\\",\\\"target_commit_sha\\\":\\\"abc123def4567890abc123def4567890abc123de\\\",\\\"expected_head_sha\\\":\\\"0123456789abcdef0123456789abcdef01234567\\\",\\\"commit_message\\\":\\\"Reset branch\\\",\\\"author\\\":{\\\"name\\\":\\\"Docs Bot\\\",\\\"email\\\":\\\"docs@example.com\\\"}}}\\n\"")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.{cluster}.code.storage/api/v1/repos/restore-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\\\",\\\"target_commit_sha\\\":\\\"abc123def4567890abc123def4567890abc123de\\\",\\\"expected_head_sha\\\":\\\"0123456789abcdef0123456789abcdef01234567\\\",\\\"commit_message\\\":\\\"Reset branch\\\",\\\"author\\\":{\\\"name\\\":\\\"Docs Bot\\\",\\\"email\\\":\\\"docs@example.com\\\"}}}\\n\""
response = http.request(request)
puts response.read_body{
"commit": {
"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>"
}
}{
"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>"
}{
"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>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}