没有不值得去解决的问题,也没有不值得去学习的技术!

Reset to the Latest Valid Commit With TortoiseGit

Decided to remove the commits that might contain conflicting files and reset the version to the latest valid commit

1. In a developer’s commit, conflicting files were present, and the code was force-committed without manually resolving the conflicts, as shown in Figure 1.

In a developer's commit, conflicting files were present, and the code was force-committed without manually resolving the conflicts
Figure 1

2. I decided to remove the commits that might contain conflicting files and reset the version to the latest valid commit, as shown in Figure 2.

Decided to remove the commits that might contain conflicting files and reset the version to the latest valid commit
Figure 2

3. Select Hard Reset to directly discard all changes from subsequent commits, as shown in Figure 3.

Select Hard Reset to directly discard all changes from subsequent commits
Figure 3

4. Reset successful, as shown in Figure 4.

Reset successful
Figure 4
Plaintext
git.exe reset --hard 086fc817cc3d149adf8ebc0489d75b3958ea111f --

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

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

5. The local files have been reverted to the latest valid commit, and the conflict prompts have disappeared, as shown in Figure 5.

The local files have been reverted to the latest valid commit, and the conflict prompts have disappeared
Figure 5

6. When pushing, a prompt appears indicating that the code must be pulled first. However, pulling the code should not be done at this point; otherwise, the files with conflicts will be pulled down again, as shown in Figure 6.

When pushing, a prompt appears indicating that the code must be pulled first. However, pulling the code should not be done at this point; otherwise, the files with conflicts will be pulled down again
Figure 6
Plaintext
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 did not exit cleanly (exit code 1) (2657 ms @ 2019/03/18 18:30:15)


7. Force push the content to the remote server, as shown in Figure 7.

Force push the content to the remote server
Figure 7
Plaintext
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)

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




8. Viewing the commit log on the Git server in Gitlab, I found that the latest commit ID has been reverted to: 086fc817cc3d149adf8ebc0489d75b3958ea111f, as shown in Figure 8.

Viewing the commit log on the Git server in Gitlab, I found that the latest commit ID has been reverted to: 086fc817cc3d149adf8ebc0489d75b3958ea111f
Figure 8

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系