问题背景

我fork了仓库,新建了fix_patch_xxx分支来解决问题 然后pull request提交到apache/eventmesh
(一般fork的仓库的master分支是不直接开发的 用来保持和源仓库的代码一致)
此时 马大哈本地commit完了之后没有设置这个分支的upstream,导致使用git GUI的时候直接推送到了master分支上。(1 commit behind是因为其他分支已经将pr合到主仓库中了)

尝试解决
- git revert
git revert
用于远程回退git reset
用于本地回退
两者的一个重要区别是前者会留一次commit,后者不会留:

凸(艹皿艹 ) 变成两个commit了,并且可以看到commit信息是revert上次commit
- 用git自带的discard
点了半天没啥反应 或者是有冲突?
- 尝试解决第二种方案的冲突问题

悲 把上面的revert的又merge回来了
(纯属本人不熟悉操作,如有会的小伙伴希望能评论区指点 感谢)
高人指点
简而言之:将你自己fork的仓库作为远程,原来的主仓库作为源,强制push。



(出错的原因是仓库master分支有protect rule,在仓库的settings中可以关闭)
这样就可以解决了!
后续思考

既然有这样的upstream和origin了,为啥不直接强制用upstream更新origin!?
在Git中,你可以使用以下命令强制将 upstream 分支的代码更新到 origin 分支:
sql
git fetch upstream
git checkout your_branch_name
git merge -Xtheirs upstream/remote_branch_name
git push origin your_branch_name
上述命令的步骤是:
git fetch upstream
:从 upstream 远程仓库获取最新的代码。git checkout your_branch_name
:切换到你的本地分支。git merge -Xtheirs upstream/remote_branch_name
:合并 upstream 分支到你的本地分支。这里使用了-Xtheirs
选项,表示在合并冲突时优先选择 upstream 分支的更改。git push origin your_branch_name
:将更新后的本地分支推送到 origin 远程仓库。