1、在某位开发人员的提交中,存在了已经冲突的文件,且未手动解决冲突,就强制提交了代码,如图1

图1

2、决定将可能存在冲突文件的几次提交给删除,重置版本至最新的一次有效提交,如图2

图2

3、选择硬重置,所有之后的 commit 的修改直接丢弃,如图3

图3

4、重置成功,如图4

图4

git.exe reset --hard 086fc817cc3d149adf8ebc0489d75b3958ea111f --

HEAD is now at 086fc81 Merge remote-tracking branch 'origin/develop' into develop

成功 (593 ms @ 2019/03/18 18:21:37)

5、本地文件已经还原至最新的一次有效提交,冲突提示已经消失,如图5

图5

6、推送时,提示需要先拉取代码,但是此时是不应该拉取代码的,否则,又会将存在冲突的文件给拉取下来,如图6

图6

git.exe push --progress "origin" develop

To https://gitlab.chinamcloud.com/php/pcs-api.git
! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to 'https://gitlab.chinamcloud.com/php/pcs-api.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


git 未能顺利结束 (退出码 1) (2657 ms @ 2019/03/18 18:30:15)

7、强制将内容推送到远程服务器,如图7

图7

git.exe push --force-with-lease --progress "origin" develop

Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for develop, visit:
remote:   https://gitlab.chinamcloud.com/php/pcs-api/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote:
To https://gitlab.chinamcloud.com/php/pcs-api.git
+ b04e465...086fc81 develop -> develop (forced update)

成功 (4156 ms @ 2019/03/18 18:51:42)



8、在 Gitlab 上查看 Git 服务器上的提交日志,发现最新的提交ID已经还原至:086fc817cc3d149adf8ebc0489d75b3958ea111f,如图8

图8

 

永夜