This is a series of articles on how to learn Git: githug. If you are reading it for the first time, you should read it first.

Today I will take you through levels 11 to 20. If you have questions about any of the commands, see the recommended tutorial in the first article.

The eleventh shut



In Git, when creating a new file, use gitgit addTo tell Git to delete a file.

The twelfth shut

Sometimes during the add operation, extra files are added. You need to remove them from the staging area, but you can’t delete them. A git help rm search for cached shows that it has this parameter, which is exactly what we need.

--cached
    Use this option to unstage and remove paths only from the index. Working tree files, whether modified or
    not, will be left alone.Copy the code

Article 13 clearance

This level scenario is also very common, think back to when we used CVS or SVN. You’re in the middle of writing a new requirement when your supervisor comes to you and says a customer has called with an urgent problem. My previous practice was to “copy” the current modified file and put it elsewhere, restore the code to the unmodified state, and check out the code corresponding to the production environment. Locate and fix the problem, commit the code, confirm that the problem is fixed and then merge back into the development branch, and copy the previously backed up code to merge.

Stash solves that problem. You just need togit stashIt “copies” the currently uncommitted changes to another location and stores them temporarily until it is ready to be restoredgit stash popCan.

The 14th off

There are two solutions to this level. The first is:

mv oldfile.txt newfile.txt
git rm oldfile.txt
git add newfile.txtCopy the code

This is obviously a bad user experience, and Linux certainly doesn’t design software this way.

The second way:

git mv oldfile.txt newfile.txt

15 off

This level is an enhanced version of the previous level and allows you to move files in batches together with wildcards.

The sixteenth shut

Sometimes we need to look at the commit history of the code, for exampleCode ReviewFrom time to time.

But Git comes with itgit logThe command is weak. Use a GUI client or TIG.

17 closing

18 close

git pushThe command does not push Tags by default.

19 closing

What should I do if SOME files are missing after submission?

Often, many people will choose to commit again, which is not reasonable. The previous commit will be incomplete, and it may fail after entering CI.

Amend is a good thing:

After the command is executed, the default editor will be invoked to edit the Commit Message, which will automatically strip out the previous message. If you do not need to modify the commit message, you can simply save and exit.

20 shut

The default commit time is the current system time, but this level requires the commit date to be overridden. I can’t think of a scenario where you need to do that. Be a little nefarious. Maybe you put Friday’s submission date on the weekend, so you’re working on the weekend. It’s pure YY. Don’t learn it, and don’t tell anyone I taught you. Git help commit

--date=
    Override the author date used in the commit.Copy the code

That’s all for today. If you want to be updated first, please check out codingstyle.cn!