赞
踩
第一步: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)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。