Pass these 54 levels and light up your Git skill tree (2)

Time:2022-9-23

This is a series of articles introducing a great tool for learning Git – githug, if you see it for the first time, please read it first:
Pass these 54 levels and light up your Git skill tree
Pass these 54 levels and light up your Git skill tree (1)

Today I will take you through levels 11 – 20. If you have questions about any of the commands, see the recommended tutorials in the first post.

level eleven

Pass these 54 levels and light up your Git skill tree (2)
In git, when creating a new file, usegit addTo tell git, similarly, when deleting a file, also tell git.
Pass these 54 levels and light up your Git skill tree (2)

Level 12

Sometimes when performing the add operation, an extra file is accidentally added into it. At this time, we need to remove it from the staging area, but the file cannot be deleted.
passgit help rm,searchcached, you can see that there is this parameter, which just meets our needs.

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

Pass these 54 levels and light up your Git skill tree (2)

level thirteen

The scene of this level is also very common, think back to when we used CVS or SVN in the past.
You write a new requirement with positive High, and suddenly your supervisor finds you and says that a user calls and encounters a problem, which is very urgent.
My previous approach was to “copy” a copy of the currently modified file and put it elsewhere, restore the code to its unmodified state, and check out the code corresponding to the production environment.
Locate and fix the problem, submit the code, confirm that the problem is fixed, and then merge it back into the development branch, and copy the code that was backed up before for merging.

stash solves this problem exactly, just needgit stash, it “copy” the currently uncommitted changes to another place and temporarily store them, and execute them when you want to restore themgit stash popThat’s it.
Pass these 54 levels and light up your Git skill tree (2)

Level 14

There are two solutions to this problem, the first is:

mv oldfile.txt newfile.txt
git rm oldfile.txt
git add newfile.txt

Obviously this is a bad user experience, and Linux definitely doesn’t design software that way.

Second approach:
git mv oldfile.txt newfile.txt
Pass these 54 levels and light up your Git skill tree (2)

Level 15

This level is equivalent to an enhanced version of the previous level, and you can use wildcards to move files together in batches.
Pass these 54 levels and light up your Git skill tree (2)

Level 16

Sometimes we look at the commit history of the code, such asCode Reviewwhen.
But git comes withgit logThe command is weak, a GUI client or tig is recommended.
Pass these 54 levels and light up your Git skill tree (2)

Level 17

Pass these 54 levels and light up your Git skill tree (2)

Level 18

git pushThe command will not push Tags by default, and parameters need to be added.
Pass these 54 levels and light up your Git skill tree (2)

Level 19

Sometimes I find that some files are missing after submitting, what should I do?
Often many people will choose to submit again separately. This is actually unreasonable. The previous commit is incomplete, and it may hang up after CI.
Good practice is to amend:
Pass these 54 levels and light up your Git skill tree (2)

After the command is executed, the default editor will be called to edit the commit message, and it will automatically bring out the previous message. If no modification is required, just save and exit.

Level 20

By default, the current system time is recorded when submitting, but this level requires that the submission date be overridden.
I can’t think of any scenario where this is needed, it’s a bit evil, it’s possible that you write the commit date on Friday as a weekend, which means you’re working overtime on the weekend.
Pure YY, don’t learn, don’t tell others that I taught you.
git help commit,searchdate

--date=<date>
    Override the author date used in the commit.

Pass these 54 levels and light up your Git skill tree (2)

That’s it for today, if you want to get updates as soon as possible, please followCodingStyle.cn