删除Commit记录
创建个临时目录,进入
git初始化,创建个占位空文件,添加commit
1 2 3 4
| git init copy nul placeholder git add -A git commit -m "First commit"
|
强制推送到远程分支
1
| git push -u 远程仓库地址 HEAD:远程分支 --force
|
当然,以上操作在删除commit记录的同时会删除所有文件
如果不想删除文件,可以先将仓库clone下来,删除.git隐藏文件夹再初始化、添加commit、推送
注意:由于git的缓存机制,删除的commit记录在一段时间内仍能访问(unreachable commits)
删除Actions和Deployments
网站上没有批量删除的功能,这里写个脚本调用API实现批量删除
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import requests
token = '此处填写token' repo = '此处填写仓库'
headers ={ 'Accept':'application/vnd.github+json', 'Authorization':f"Bearer {token}", 'X-GitHub-Api-Version':'2022-11-28' }
print('开始删除Actions')
while True: response = requests.get(f"https://api.github.com/repos/{repo}/actions/runs?per_page=100") response.raise_for_status() response = response.json() if(response['total_count'] == 0): print('删除完成') break for action in response['workflow_runs']: response = requests.delete(f"https://api.github.com/repos/{repo}/actions/runs/{action['id']}", headers = headers) print(f'删除 {action['run_number']}', end=" ") if response.status_code == 204: print('成功') else: print(f'失败({response.status_code})')
print('开始删除Deployments')
while True: response = requests.get(f"https://api.github.com/repos/{repo}/deployments?per_page=100") response.raise_for_status() response = response.json() for deployment in response: response = requests.delete(f"https://api.github.com/repos/{repo}/deployments/{deployment['id']}", headers = headers) print(f'删除 {deployment['id']}', end=" ") if response.status_code == 204: print('成功') else: print(f'失败({response.status_code})') print('删除完成') break
|