Home > Article > Development Tools > 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 usedclone,
add,
commit,
push,
pull and other commands; there is also rollback Command
reset. 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 inPayment 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.
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:
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 classTaskListener could not be submitted after changing it. I accidentally committed it to the local. (Not pushed to remote yet).
git log
239afed0857cc2e77c17c01014077808619af64d, and all commits after this version will be cancelled.
git reset --hard commit_id //退到/进到 指定commit的sha码 commit_id:239afed0857cc2e77c17c01014077808619af64d3.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
.
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!