Using the GitHub API, I can create a tree containing all the modified files for a commit, specify a base_tree
that will be updated with this tree of changes and then commit it.
But, as the documentation says, the new tree can contain only paths for files with the modes
100644
for file (blob),100755
for executable (blob),040000
for subdirectory (tree),160000
for submodule (commit), or120000
for a blob that specifies the path of a symlink.
It doesn't say what should I do if I want to mark some path as deleted, as with git rm <path>
.
Currently, the only way to remove an entry from the tree (either a blob or another tree) is to construct a new tree and not list that entry. After you have that tree, construct a new commit that links to this new tree, and don't forget to bump the ref to point to this new commit.
@ivan-zuzak 's answer is obsolete now that the GitHub API supports deleting files by passing null sha's.
To delete a file you would create a tree in Javascript with octokit like so:
await octokit.request('POST /repos/{owner}/{repo}/git/trees', {
owner: 'octocat',
repo: 'hello-world',
tree: [
{
path: 'path/to/file-that-will-be-deleted.py',
mode: '100664',
type: 'blob',
sha: null,
}
],
base_tree: 'sha'
})
The base_tree should contain the SHA1 of an existing Git tree object you want to delete the file from.
After that everything Ivan said still holds true, so you should construct a new commit that links to this new tree, and bump the ref to point to this new commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With