git rebase 合并多个 commit 后,无法 push 到 origin 上

40 天前
 chenzw2

git 上有 5 条 commit 记录,我用 git rebase 将 5 条 commit 记录合并成了 1 条,这时使用 git push -f origin main 进行推送却报错:

git push -f origin develop Enumerating objects: 48, done. Counting objects: 100% (48/48), done. Delta compression using up to 12 threads Compressing objects: 100% (19/19), done. Writing objects: 100% (26/26), 4.52 KiB | 385.00 KiB/s, done. Total 26 (delta 12), reused 0 (delta 0), pack-reused 0 remote: GitLab: You are not allowed to force push code to a protected branch on this project. To https://xxx.xxx.xxx.git ! [remote rejected] develop-norm -> develop (pre-receive hook declined) error: failed to push some refs to 'https://xxxx.xxxx.xxxx.git'

2417 次点击
所在节点    git
27 条回复
chenzw2
40 天前
可以了,设置中临时允许强制推送,推送成功,感谢各位大佬!
lovelylain
40 天前
rebase 后要 push -f ,一般用于发布前把 master 分支最新修改合并进开发分支且使开发分支的提交记录清爽,如果开发分支也不允许 push -f 的话,就不能用 reabse
2123123
40 天前
我认为 rebase -i 跟 rebase 完全不是一回事也没必要混到一起说
平时使用 pull --rebase 或者用 rebase 正确合并两个分支不会需要用到 force push
与 merge 不同,rebase 是有顺序的
ooops
39 天前
即使 --force 也要用 --force-with-lease
kneo
39 天前
自己私人的项目,并且完全没有别人 clone 过,可以强制 push ,其它情况不建议。
buhaoban
39 天前
通过 PR 方式来 force push, 这样既可以保护 main/master, 也方便以 PR 为单位管理功能开发。
guanzhangzhang
38 天前
哈哈哈,仔细看看报错,就是不允许强推,在多人合作和项目开发里,release 和 master/main 是有保护的,都是自己分支上 rebase 成一个 commit ,或者 git pull --rebase origin/master 后再 push -f 的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1033881

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX