我想在 GitHub 存储库上创建(推送)新文件,而不需要git
工具,(因为git
我的工具不可用PHP
主持人)。所以我做了一些研究,发现GitHub REST API https://docs.github.com/en/rest.
我尝试使用curl
使用个人访问令牌来上传或修改我的存储库上的文件。here is https://gist.githubusercontent.com/aborruso/40aee4f1738c0a0e3727bf7cbec91152/raw/9458c7ff7e5402bb404e2e1fd29a3bb5dd6f162d/updatefile.sh我找到并进行更改的 shell 代码curl
像下面这样:
curl -i https://api.github.com/repos/username/repo/newFile.txt -X PUT
\ -H 'Authorization: token xxxxxxxxxxxxxxxxxxxx' -d "{\"path\": \"newFile.txt\",
\ \"message\": \"update\", \"content\": \"$(openssl base64 -A -in newFile.txt)\", \"branch\":
\"master\",
\ \"sha\": $(curl -X GET https://api.github.com/repos/username/repo/newFile.txt | jq .sha)}"
但我收到此错误:
HTTP/1.1 404 未找到
服务器:GitHub.com
我该如何解决这个问题?
附:即使有一个push file by email
GitHub 或 (GitLab) 上的服务,这可以帮助通过电子邮件在我的存储库上创建文件。
我把我的工作curl
在这里,如果有人需要这个。
为了方便推送,最好将你的文件放入base64格式 (base64 {filename}
or 在线工具 https://www.google.com/search?q=make%20file%20in%20base64%20online) 进而:
curl -X PUT -H "Authorization: token xxxxxxxxxxxxxxxxxxxx" https://api.github.com/repos/{owner}/{repo}/contents/{path}/{fileName} -d "{\"message\":\"your commit message\",\"content\":\"your file in BASE64\"}"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)