当前位置:网站首页>[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 ...

90eb2565066575364f264267f1b27423.png

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 HEAD

The 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 directly  Git  Automatically 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/eboo‍ks

$ 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-xuan‍

Be 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 feature

The 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 ------

6a4a923940d102f50263ac01122d5a3d.png Excellent materials , Great benefits !8bc5288820022217f9666acad1370c7b.png

>Java Interview questions <
3000+ Online brushing of test questions on the pavement , newest 、 The most complete Java Interview questions !

5a19e28fb49e14eb6cc1c747a1d05f1c.png

7fb9183cfce3d6073f5437111cca8345.png

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 ?

【264 period 】 Interviewer asked :Spring Boot There are several ways to automatically execute code at startup ? Explain one or two !

【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 ?

cfac055d3f8bbe11bd3f5df648306b9d.png  technology Communication group !045511c7c539210e8ffda27bf081a8ad.png

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! !

原网站

版权声明
本文为[Java collection]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203012117314311.html