Azure DevOps上使用git管理代碼,發現上次push到遠程的代碼有點小問題,本地amend修改好上次提交以后,想把遠程的提交覆蓋掉,Force push發現不能生效,報錯如下
$ git push -f
Total 0 (delta 0), reused 0 (delta 0)
To ssh.dev.azure.com:v3/orgName/projectName/repoName
! [remote rejected] feature/branch -> feature/branch (TF401027: You need the Git 'ForcePush' permission to perform this action. Details: identity 'XXXX@xxx.xxx', scope 'branch'.)
error: failed to push some refs to 'git@ssh.dev.azure.com:v3/orgName/projectName/repoName'
定位到Branches頁面,打開相應branch的Branch security
設置,找到自己所在的用戶組,比如說Contributor,設置允許Force push
搜索框輸入自己的賬號,看下最終評估結果是不是允許Force push(有時候可能弄錯自己所在的用戶組,有時候會因為用戶組設置相互覆蓋而不生效),這里只是用來確認自己設置的允許Force push確實生效了。
※如果直接搜索自己的賬號去設置,有些情況下可能並不生效(用戶組設置相互覆蓋),完成后再次搜索,可能會像如下一樣,發現狀態並不正確,push會報如上一樣的錯誤
修改完再次push發現還是不行(注意到branch上有policy徽標)
$ git push -f
Total 0 (delta 0), reused 0 (delta 0)
To ssh.dev.azure.com:v3/orgName/projectName/repoName
! [remote rejected] feature/branch -> feature/branch (TF402455: Pushes to this branch are not permitted; you must use a pull request to update this branch.)
error: failed to push some refs to 'git@ssh.dev.azure.com:v3/orgName/projectName/repoName'
再次定位到Branches頁面,打開相應branch的Branch Policies
設置,發現了以下policy
關閉勾選的項,再次push,終於可以了
$ git push -f
Total 0 (delta 0), reused 0 (delta 0)
To ssh.dev.azure.com:v3/orgName/projectName/repoName
+ 5a3b351...c8fa643 feature/branch -> feature/branch (forced update)