Article From:https://www.cnblogs.com/stdio0/p/9967356.html

While I was watching TV, my cat jumped onto my laptop, stepped on a few feet and ran away. When I returned to my computer after watching TV, I was surprised to find that the original document I had just submitted to the warehouse had been deleted and saved in a pile of random codes! uuuuuuuuuu Now my file looks like this:
1.png

What can I do about it? Although I hit the cat with a cat snack, it broke my heart to lose such a good article. After feeling the ultimate loneliness and helplessness, I thought of the Git housekeeper. Even in times of extreme sadness, as successors to socialism, our courtesy is indispensable.After all, it represents our good looks. First, we need to use it on the command line.git statusSay hello to the Git housekeeper (remember, you must switch to the directory where you created the project before entering the command).
2.png

GitThe housekeeper responded: There is nothing on the list that needs to be submitted. You can use it.git add <The file name is >To submit the document to the list first, or to usegit checkout -- <The file name is >Restore the changes in the modified files.

I did see a play! So usegit checkout -- 2022-02-22.txtCome and try to restore, reopen and discover what I had before, and sure enough, it’s back again! uuuuuuuuu It’s simply beautiful!

So I continued to write, striving to complete this masterpiece as soon as possible! This is what I continue to write. Dule is not as good as Zhongle. Send it out to let you feel it.
3.png

After writing it, I feel like it’s really refreshing and refreshing. It is then submitted to the Git repository using the following commands in turn:

git status   //View version changesGit add. // Add all files to the Git listGit commit-m "Eat Pineapple, Eat Orange"// Formally add documents to Git warehouse

Second steps here.git add .The dot in the list means that all the changed and new files are added to the list of gits. Because sometimes our project may change dozens of documents at the same time to use the previous ones.git add <The file name is >If you add them one by one, you may run away.

When I submitted the revised works to Git warehouse, I went to the movies. On the way home from the movies, I saw a roast chicken hanging in a big stall window in China. I was too shy to eat it. So I returned home ashamed and dreamed that I could finish eating a whole roast chicken one day. This timeRemembering that I was writing a diary for myself in the future, I decided not to eat oranges after eating pineapple. I wanted to eat a whole roast chicken! But as an excellent writer, I don’t want to delete the content of my writing word by word, otherwise it will appear very unparalleled. What should I do?Then I thought of the Git housekeeper. This greeting is used because it’s not about committing a transaction, it’s about rolling back the file to its previous state.git log,Git housekeeper, show me your account book.
4.png

Here we can see that there are two records. The following one is the earliest “add 2022-02-02 diary”, and the last one is “add 2022-02-02 diary”.

Speaking back to our original topic, from the time point of view of the time version, I can confirm that the following record is the version I need to roll back! So I used it.git reset --hard b863,Let the Git Butler help me roll back the version to its previous state.

Interpretation: reset means reset – – hard means that all files are restored, while b863 is the first four digits after the version commit I need to roll back. You can also enter all the version numbers, but I usually use only four digits for rollback here, if you haveSpecial hobbies can be completely entered into the version number. At this time, my document has returned to the original version, and my creative path has been continued! uuuuuuuuuuu Let’s see what I’ve done with the document.
8.png

– & gt; Rollback of uncommitted files:

git status  // Check that file has been modified.Git checkout -- lt; filename & gt; // rollback the file you want to undo the modification

If you want to roll over multiple files, you can use something like add. Here you can also use a dot instead of the file name.

– & gt; Rollback of submitted files:
git log  // View the historical version of the Git projectGit reset - hard & lt; the first four digits of the version & gt; // roll back the project to your specified version
Link of this Article: Chapter 3 Local Project Rollback

Leave a Reply

Your email address will not be published. Required fields are marked *