当前位置:网站首页>[issue 268] accidentally submit the test code to the production environment. I will teach you six ways to solve it in seconds!
[issue 268] accidentally submit the test code to the production environment. I will teach you six ways to solve it in seconds!
2022-06-11 13:37:00 【Java collection】
Click on the above “Java selected ”, choice “ Set to star ”
Don't ask people why , Ask yourself why !
below Have a pleasant surprise , A message will be back , Have a craigslist !
Make progress every day , It's the beginning of success ...

Git Version management , It's often necessary to undo certain operations .
This article introduces some of the most important situations , Give a detailed explanation .
One 、 Cancel the submission
A common scenario is , After submitting the code , You suddenly realized there was a problem with this submission , It should be cancelled , At this time, execute the following command .
$ git revert HEADThe principle of the above command is , After the current submission , Add a new submission , Offset all changes caused by the last commit . It will not change the history of the past , So it's the first choice , There is no risk of losing code .
git revert The command only cancels out the last commit , If you want to offset multiple submissions , These commits must be specified in turn on the command line . such as , Offset the first two submissions , Write like this .
$ git revert [ The last one to submit ] [ The penultimate submission ]git revert The command also has two parameters .
--no-edit: Do not open the default editor when executing , Use it directlyGitAutomatically generated submission information .--no-commit: Only offset file changes in staging area and workspace , No new submissions .
Two 、 Discard commit
If you want the previous submission to disappear completely in history , Instead of being offset , have access to git reset command , Discard all submissions after a submission .
It's recommended to stay up late and tidy up in the next few months 10000+ Interview materials :https://gitee.com/yoodb/ebooks
$ git reset [last good SHA]git reset The principle is , Let the newly submitted pointer go back to a previous point , All submissions after that time point have disappeared from history .
By default ,git reset Don't change the workspace file ( But it will change the staging area ),--hard Parameters can return files in the workspace to their previous state .
$ git reset --hard [last good SHA] perform git reset After the command , If you want to retrieve those discarded submissions , have access to git reflog command , Refer to here for details . however , This kind of practice has timeliness , It's been a long time, maybe I can't find it .
3、 ... and 、 Replace last commit
After submission , I found that the submitted information was wrongly written , You can use git commit Ordered --amend Parameters , You can modify the last submitted information .
$ git commit --amend -m "Fixes bug #42"Its principle is to generate a new submission object , Replace the submission object generated by the last submission .
At this time, if there are files in the staging area that have changed , Will be submitted to the warehouse together . therefore ,--amend Not only can you modify the submitted information , You can also replace the last submission with the whole one .
Four 、 Undo file changes in workspace
If a file in the workspace is messed up , But it hasn't been submitted yet , It can be used git checkout Order to retrieve the documents before this modification .
$ git checkout -- [filename]Its principle is to find the temporary storage area first , If the file has a temporary version , Then restore the version , Otherwise, restore the last submitted version .
Recommend your own Spring boot The actual project of :
https://gitee.com/yoodb/jing-xuanBe careful , Once the file changes in the workspace have been undone , You can't find it .
5、 ... and 、 Undo file from scratch
If you accidentally add a file to the staging area , You can undo... With the following command .
$ git rm --cached [filename]The above command does not affect what has been submitted .
6、 ... and 、 Undo changes in the current branch
You have made several submissions on the current branch , Suddenly I found the wrong Branch , These commits should have been placed in another branch .
# Create a new one feature Branch , Point to the current latest commit
# Be careful , It's still in the current branch
$ git branch feature
# Switch to the state before these commits
$ git reset --hard [ The last previous commit of the current branch ]
# Switch to feature Branch
$ git checkout featureThe above operation is equivalent to undo the change of the current branch , Put these changes in a new branch .
author : Ruan Yifeng
https://url.cn/5NLK2pC
official account “Java selected ” The published content indicates the source of , All rights reserved ( Those whose copyright cannot be verified or whose source is not indicated all come from the Internet , Reprinted , The purpose of reprinting is to convey more information , The copyright belongs to the original author . If there is any infringement , Please contact the , The author will delete the first time !
------ THE END ------
Excellent materials , Great benefits !
>Java Interview questions <
3000+ Online brushing of test questions on the pavement , newest 、 The most complete Java Interview questions !


Hope to select Click on the title to jump to
【260 period 】PageHelper Use ThreadLocal Thread reuse problem , Did you use it right ?
【261 period 】 Why? BigDecimal Class cannot use equals() Methods to make equivalence comparison ?
【262 period 】 interviewer :jwt What is it? ?java-jwt Well ? Stupid ...
【263 period 】 Interviewer asked : Suppose there are 10 million data , How to quickly query ?
【265 period 】 interviewer : list 8 Kind of Docker Application scenarios , What do you know about ?
【266 period 】 Interviewer asked : Why? SQL Try to avoid using IN and NOT IN?
【267 period 】Spring Boot How to integrate WebSocket Realize group chat , One on one chat ?
technology Communication group !
Many people have asked recently , Is there any readers Communication group ! Want to know how to join ? It's very simple , Friends with similar interests , Just click on the card below , reply “ Add group ”, that will do No routine Join the communication group !
If the article helps , Looking at , Forward! !
边栏推荐
- 优化调度(火电、风、储能)(Matlab实现)
- Network information system emergency response
- Huawei HECs ECS is used to build a telegraf+influxdb+grafana monitoring system [Huawei cloud to jianzhiyuan]
- Shader shader
- JSP implementation of performance appraisal system for bank counter business
- Nomad application scheduling scheme 08 of hashicopy (detection job)
- 如何写出高性能代码(四)优化数据访问
- d区间到可空转换
- How to manage the server to make the website stable and smooth
- Explanation of waitgroup usage in go language learning
猜你喜欢

AGV机器人RFID传感器CK-G06A与西门子1200PLC应用手册

The application of machine learning in database cardinality estimation

Explain in detail the differences between real participation formal parameters in C language

Collapse expression

Ecplise cannot connect to SQL Server

cadence SPB17.4 - group operation(add to group, view group list, delete group)

Three level classification display

面试造航母,入职拧螺丝,工资...

Using vscode code code template to improve mobx coding efficiency

Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!
随机推荐
The tree (AVL, 2-3-, red black, Huffman)
Introduction to reverse learning - excellent assembly debugging tool OllyDbg
论文导读 | 机器学习在数据库基数估计中的应用
Customize terrain providers (terrain plugin framework) -04
Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)
【系统分析师之路】系统分析师错题章节集锦
Explain in detail the differences between real participation formal parameters in C language
Unity 检测对象是否在相机的视锥体范围内
NFT市场怎么样 为什么NFT能如此火爆 怎么搭建NFT平台
Using vscode code code template to improve mobx coding efficiency
Today in history: Apple II comes out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born
create_ Error in engine MySQL connector encryption method
Unsealing easy QF PDA helps enterprises improve ERP management
全球手机市场衰退,连苹果也对iPhone14不抱过高期待
高比例风电电力系统储能运行及配置分析(Matlab实现)
VIM secondary replacement
Pki/tls Swiss Army knife cfssl
2022工具钳工(中级)操作证考试题库及答案
How to manage the server to make the website stable and smooth
Huawei HECs ECS is used to build a telegraf+influxdb+grafana monitoring system [Huawei cloud to jianzhiyuan]