Home  >  Article  >  Development Tools  >  How does GIT roll back to a commit?

How does GIT roll back to a commit?

Guanhui
Guanhuiforward
2020-07-23 17:57:1812788browse

How does GIT roll back to a commit?

##Preface

At work, the use of Git becomes more and more Come more and more often. . In addition to the most commonly used

clone, add, commit, push, pull and other commands; there is also rollback Commandreset. This blog will record the simple use of this rollback command.

Scenario

Because during the company's development process, Alibaba Cloud's message queue MQ is used when processing orders, limited-time purchases, etc. realized. Or the interaction between two systems, synchronizing information, for example, the user places an order in

Payment System A (payment is successful). At this time, Payment System A not only processes the order, but also sends orders to Inventory system B sends a message to inform Inventory system B to reduce the inventory of the ordered goods.

When I run the project locally, if I do not comment out the

Listener, the messages on the test server may also be sent to my local computer, causing the message to be lost. Then~~I commented out the local listener code to facilitate testers to test on the test server. Comment out the code as shown below:

Haha~~ After commenting it out, when I submitted it, I submitted it together! How embarrassing! The tester reported a bug!

Looking at the code submission history~~ the message listener was commented out by me. I'll take the blame! (Laughing and crying)

solve the problem

Oops. . . What I said above seems to be inconsistent with what this article is about to say.

Actually, it was during development. I accidentally submitted code that should not be submitted to the local. For example, the class

TaskListener could not be submitted after changing it. I accidentally committed it to the local. (Not pushed to remote yet).

It may have been committed to the local area multiple times.


1. First check the commit log and execute the following command

git log


2. Roll back and cancel the previous commit


Here we assume that we should roll back to

239afed0857cc2e77c17c01014077808619af64d, and all commits after this version will be cancelled.

git reset --hard commit_id  
 //退到/进到 指定commit的sha码 commit_id:239afed0857cc2e77c17c01014077808619af64d

3.ok, you can resubmit

git commit a.txt -m "重新提交"  
// 记得不要提交不想提交的文件哦

IDEA RESET

You can also use IDEA’s## directly #Reset Head

function, first get the commit_id to be rolled back through git log, and then perform the screenshot below. You can validate it first and see if you can find this submission through commit_id.


##Summary

Development During the process, you will always accidentally submit some documents that cannot be submitted. . If you use IDEA for development, you can take a look at this function of IDEA - it is practical, and you no longer have to worry about submitting the wrong submission.

Recommended tutorial: "

Git Tutorial

"

The above is the detailed content of How does GIT roll back to a commit?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete