当前位置:网站首页>[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! !
边栏推荐
- Some transformation thoughts of programmers after they are 35 years old
- cadence SPB17.4 - allegro - allegro_free_viewer
- Nomad application scheduling scheme 08 of hashicopy (detection job)
- Setting tcp/ip network in Debian
- Explain in detail the differences between real participation formal parameters in C language
- kubernetes 二进制安装(v1.20.15)(六)部署WorkNode节点
- 面试造航母,入职拧螺丝,工资...
- cadence SPB17.4 - group operation(add to group, view group list, delete group)
- 阿里一面,谈谈策略模式在项目中的使用
- What do you need to do to "surpass" the general database in the time sequence scenario?
猜你喜欢

關於分布式鎖的續命問題——基於Redis實現的分布式鎖
Explanation of waitgroup usage in go language learning

On the life extension of distributed locks -- redis based distributed locks

全球手机市场衰退,连苹果也对iPhone14不抱过高期待

On the continuing Life of Distributed Locks - - Distributed Locks Based on redis
![[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]](/img/1a/7b80f3d81c1f4773194cffa77fdfae.png)
[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]

Business practice of volcano engine cloud database VEDB in bytes

JDBC连接池去做批量导入,每次运行500万数据,但是在中间就会出各种问题

Why does each running Department display that the database already exists, delete the database, and then succeed? Each running department must delete the database, and re run the whole successfully

31W contest question bonus! When AI for Science collides with the "pilot Cup", what sparks will be generated?
随机推荐
31W contest question bonus! When AI for Science collides with the "pilot Cup", what sparks will be generated?
Can't understand kotlin source code? Starting with the contracts function~
How to learn to spend money
About PHP: the original deployment environment written by PHP is deployed in phpstudy, PHP + MySQL + Apache. However, the computer must be turned on every time
Ali talked about the use of strategic mode in the project
Introduction to long connection
Explain in detail the differences between real participation formal parameters in C language
The tree (AVL, 2-3-, red black, Huffman)
[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]
[backtrader source code analysis 46] cerebro Py code comments (boring, one of the core backtrader codes, recommended for reading, comments for reference only)
Explanation of waitgroup usage in go language learning
Introduction to reverse learning - excellent assembly debugging tool OllyDbg
JDBC connection pool is used for batch import. 5million data are run each time, but various problems will occur in the middle
[Multisim Simulation] 555 flash lamp experiment
Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)
cadence SPB17.4 - allegro - allegro_free_viewer
使用华为HECS云服务器打造Telegraf+Influxdb+Grafana 监控系统【华为云至简致远】
/usr/bin/gzip: 1: ELF : not found /usr/bin/gzip: 3: : not found /usr/bin/gzip: 4: Syntax erro
Interview to build an aircraft carrier, screw on the job, pay
Is the brokerage account given by qiniu business school safe? Do you charge for opening an account