Play git in a minute

Time:2021-9-12

Today, a new child asked me about the use of GIT. I found that many new people can’t use it or can’t use it well. In fact, when I was just working, I didn’t know these parameters and usage, and I was always afraid of making mistakes. I became familiar with it by reading more documents and using more. Today, I’d like to share a few points with you.

Must know add & commit

First, we need to know the three local states:

Play git in a minute

Well, I’ve written down the order.

After changing the code locally, use it

Git add file name / folder / multiple

Submit to the cache. If there are many file changes here, but not all files need to be submitted, I will setgit ignore file, which means that these files should not be submitted, such as those files that will be automatically generated when building project, etc.

Then again

git commit -m "comment"

To the local library. Usually followed by a-mAdd sentencecomment, simply put, what has been changed? Like our company, we will also change it by defaultJiraThe link is attached so that you know which task this change corresponds to.

If you want to change it again, try againgit addYes, butcommitThis sentence needs to be changed into

git commit --amend

This is also a git log message.

Log

git logYou can view the submitted log. This is mainly because if you need to move forward or backward on the version (the next step)reset), you need to usenumber

Direct run

git log

If so, a large amount of information will be displayed. From near to far, the comment of each commit, as well as the author, date and other information will be displayed. For example, it looks like this:

commit 5abcd17dggs9s0a7a91nfsagd8ay76875afs7d6
Author: Xiaoqi<[email protected]>
Date: xxx xxx xxx
Changed test file

The one behind commitnumber, is one of each historyIndexes

There are too many logs printed in this way. The more concise printing method is:

git --oneline

Just print it out on one line.

Or:

git reflog

More commonly used.

Reset

We just said that if you need to advance or return to a certain version, use

Git reset -- hard < number >

So you jump right to thisnumberThe corresponding version.

So thishardWhat does that mean?

There are three parameters:hard, soft, mixed, let’s talk about it one by one.

Back to our most important picture:

Play git in a minute

What we just said about moving forward or backward to a certain version is rightLocal libraryOperations performed.

There is a problem:
After the code of the local library jumps to that version, the code of the workspace and staging area is out of sync with that of the local library!

These parameters are used to control whether these parameters aresynchronizationof

git reset –hard xxx

The three zones are synchronized and jump to the version of XXX.

git reset –soft xxx

If the first two zones are out of sync, only the local library jumps to this version.

git reset –mixed xxx

The staging area is synchronized and the workspace is not moved.

So, hard is often used

There are many more uses of GIT. If you like this series, please give me a “Looking“Ah, so I have more motivation to write ~

Whisper: every time I arrive on Thursday, I think the weekend is coming. I think I can do more work today and get off work early tomorrow, so today’s efficiency is super high, ha ha ~

Play git in a minute