当前位置:   article > 正文

修改git历史合入记录的方法_refs/heads/main:refs/heads/main[remote rejected] (

refs/heads/main:refs/heads/main[remote rejected] (pre-receive hook declined

第一步:git rebase -i HEAD~5
    注意:如果需要修改的commit在5步以内
第二步:将需要修改的commit所在的行前面的 pick 修改为edit或者e    
    注意:不修改内容,修改内容在第三步
第三步:git commit --amend
    注意:这个时候修改内容
第四步:git rebase --continue
    结果显示:
    $ git rebase --continue
    Successfully rebased and updated refs/heads/main.
第五步:git push -f
    结果显示:
    $ git push -f
    remote: Resolving deltas: 100% (5335/5335), done.
    remote: GitLab: You are not allowed to force push code to a protected branch on this project.
    To ssh://gitlab.XXX.git
     ! [remote rejected]     main -> main (pre-receive hook declined)
    error: 推送一些引用到 'ssh://git@gitlab.XXX.git' 失败

解决方法:

        点击  Setting->Repository 菜单

        然后选择 Protected branches 并点击后面的 Expand 按钮

        最后选择后面的Unprotect

修改后重新尝试:
$ git push -f
枚举对象中: 66548, 完成.
对象计数中: 100% (66548/66548), 完成.
使用 12 个线程进行压缩
压缩对象中: 100% (60634/60634), 完成.
写入对象中: 100% (66547/66547), 178.41 MiB | 573.00 KiB/s, 完成.
总共 66547 (差异 5335),复用 65364 (差异 4994)
remote: Resolving deltas: 100% (5335/5335), done.
remote: Checking connectivity: 66547, done.
To ssh://gitlab.XXX.git
 + f21a9627a...b0d125dee main -> main (forced update)

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号