Git undoes a commit in the middle and keeps other commits

Today I went to work and my brain was pumped, let’s test directly to uat, because the project was developed by myself recently, I pulled three branches and changed different things, and finally sent it to the test branch for testing, one by one when it was released for production If you find it troublesome, just use the test branch to uat, and there will be a problem in production. The code changed by a colleague before has been combined with test, but the modification has not been completed and cannot be put into production. What should I do? See if I can withdraw his time Submit, tried a lot of ways, but finally solved it:

When you want to undo an intermediate commit, it is strongly recommended to use the revert command instead of reset.
git reset –hard commit_id Although you can roll back the remote library, it will roll back all other submitted codes and need to re-submit, so it is recommended to use the revert command to return only the content of that submission

Correct steps:

git revert commit_id
//If commit_id is a merge node, -m specifies which commit point
git revert commit_id -m 1 (for example: 'git revert 33da8c5a -m 1')
insert image description here

//Then is to resolve conflicts
git add -A
git commit -m “…”
git revert commit_id -m 2
//Then is to resolve conflicts
git add -A
git commit -m “…”
git push

Among them, git revert commit_id -m number is for the operation of merge submission point.
If it is an ordinary submission point, there is no need to be so troublesome.

Reference address:
[Git Advanced Tutorial (2)] Remote warehouse version rollback method
https://www.cnblogs.com/ShaYeBlog/p/5368064.html
https://blog.csdn.net/hongchangfirst/article/details/ 49472913

Guess you like

Origin blog.csdn.net/m0_46156566/article/details/130636634