Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.


The last article introduced some basic concepts of Git, including the history of Git, the process of collaborative development, and so on. This article will explain some basic instructions of Git.


Local library initialization

Let’s say I want to develop a project and first develop it locally. I create a Crawler folder on my desktop, go to that folder, right click, and open Git Bash:There is nothing in the folder, so we enter a command in the terminal:

git init
Copy the code

Running results:Create a Git repository that contains subdirectories and files related to the local Git repository. Do not delete or modify them.


Setting Git Signatures

Git requires developers to provide their own unique identifiers: usernames and email addresses.

Git signatures fall into two categories:

  1. Item level signature
  2. System-level signature

Project-level signatures, as the name implies, are valid only within the scope of the current local library; System-level signatures are valid for all current users in the current OPERATING system, that is, all the warehouses created by the user can use the signature.

The priority between them follows the principle of proximity: project-level signature is better than system-level signature. If both are set, project-level signature is adopted. If only a certain level of signature is set, the signature is adopted. Git specifies that a certain level of signature must be set, and neither must be set.

For item-level signatures, the set instructions are as follows:

Git config user.name Specifies the user name git config user.email Specifies the email addressCopy the code

For system-level signatures, the setup instructions are slightly different:

Git config --global user.email Git config --global user.emailCopy the code

Note that the username and signature can be set arbitrarily. You can even set up a non-existent email address, which is only used as an identifier.

Here I set up the item-level signature and enter the following command:

git config user.name blizzawang
git config user.email [email protected]
Copy the code

Git config file:To open this file:This is the signature we just set, so don’t touch anything in the.git directory.

To set the system-level signature, enter the following command:

git config --global user.name blizzawang_glb
git config --global user.email [email protected]
Copy the code

Once it’s set up, it also has a place to save it, only this time it’s not saved in the project, but in the user directory:To open this file:This is the system signature we just set up.


Add, view status, submit operations

Here are some specific operation instructions. Generally, add, view status and submit are three frequently used operations in our development process.

I first execute the following status command:

git status
Copy the code

Running results:

  • On branch Master: Indicates that we are currently On the master branch, more On the concept of branches later
  • No commits yet: Indicates that there were No commits in the local library
  • There is nothing to commit in the staging area

Git partitions:

  1. Workspace: This is the work area where directly edited files are placed
  2. Staging: A staging area is a place where data is temporarily stored, giving developers an opportunity to go back on their mistakes if they add something wrong
  3. Git is a hidden directory where many things are stored, including the index file

Here I create a test.txt file in my workspace:Check the status again:

git status
Copy the code

Running results:Because we just created the file and haven’t done anything yet, we’re still in the Master branch; There are still no commits in the local library.

But watch out for the following:

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.txt

nothing added to commit but untracked files present (use "git add" to track)
Copy the code

Nothing was committed but an untraced file was found. This is the test.txt file that was created earlier.

Since it is not traced, we trace the file with the command:

git add test.txt
Copy the code

After the trace is complete, we perform the view status operation again:

git status
Copy the code

Running results:There are still no commits for the local library, but there is a new file change that can be committed, along with a hint:

(use "git rm --cached <file>..." to unstage)
Copy the code

Git add: git add: git add: git add: git add: git add: git add: git add

 git rm --cached test.txt
Copy the code

After retracting, we recheck the status:Insert the test.txt file into the staging area and execute the command:

git add test.txt
Copy the code

Once added to the staging area, we are ready to commit the contents of the staging area to the local library by executing the following command:

git commit test.txt
Copy the code

After executing this command, the terminal switches to the following interface:Here you need to input a description of this commit, you can write this commit to do what, what functionality, for later maintenance.

The Vim editor is the default Git editor used by the Git terminal during Git installationiEnter edit mode and enter the description of this submission on the first line:iAfter the key the lower left corner will show — insert –, at this point you can start editing.

When you’re done editing, pressescKey to exit edit mode, then press the combination keyShift + :, then input the command:wq, save and exit, and the commit is complete.There’s also some information in there, which I’ll explain later.

At this point we check the status again:This indicates that the staging area is clean, there is nothing to commit, and the workspace has no state changes.

This completes the process of adding, viewing, and committing from the workspace to the staging area with the Git add command, and then committing the staging area to the version area with the Git commit command.

Let’s move on to a scenario where we created an empty file and added some text to the file:At this point we check the status again:A change was not added to the staging area.

no changes added to commit (use "git add" and/or "git commit -a")
Copy the code

You can commit with git add and git commit, or you can commit with git commit because the file has already been traced.

Git commit (Vim, Vim, Vim, Vim, Vim)

Git commit -m "test.txtCopy the code

Submission Results:The result indicates that a file has been modified and 1 line of content has been added.


The last article introduced some basic concepts of Git, including the history of Git, the process of collaborative development, and so on. This article will explain some basic instructions of Git.

Local library initialization

Let’s say I want to develop a project and first develop it locally. I create a Crawler folder on my desktop, go to that folder, right click, and open Git Bash:There is nothing in the folder, so we enter a command in the terminal:

git init
Copy the code

Running results:Create a Git repository that contains subdirectories and files related to the local Git repository. Do not delete or modify them.


Setting Git Signatures

Git requires developers to provide their own unique identifiers: usernames and email addresses.

Git signatures fall into two categories:

  1. Item level signature
  2. System-level signature

Project-level signatures, as the name implies, are valid only within the scope of the current local library; System-level signatures are valid for all current users in the current OPERATING system, that is, all the warehouses created by the user can use the signature.

The priority between them follows the principle of proximity: project-level signature is better than system-level signature. If both are set, project-level signature is adopted. If only a certain level of signature is set, the signature is adopted. Git specifies that a certain level of signature must be set, and neither must be set.

For item-level signatures, the set instructions are as follows:

Git config user.name Specifies the user name git config user.email Specifies the email addressCopy the code

For system-level signatures, the setup instructions are slightly different:

Git config --global user.email Git config --global user.emailCopy the code

Note that the username and signature can be set arbitrarily. You can even set up a non-existent email address, which is only used as an identifier.

Here I set up the item-level signature and enter the following command:

git config user.name blizzawang
git config user.email [email protected]
Copy the code

Git config file:To open this file:This is the signature we just set, so don’t touch anything in the.git directory.

To set the system-level signature, enter the following command:

git config --global user.name blizzawang_glb
git config --global user.email [email protected]
Copy the code

Once it’s set up, it also has a place to save it, only this time it’s not saved in the project, but in the user directory:To open this file:This is the system signature we just set up.


Add, view status, submit operations

Here are some specific operation instructions. Generally, add, view status and submit are three frequently used operations in our development process.

I first execute the following status command:

git status
Copy the code

Running results:

  • On branch Master: Indicates that we are currently On the master branch, more On the concept of branches later
  • No commits yet: Indicates that there were No commits in the local library
  • There is nothing to commit in the staging area

Git partitions:

  1. Workspace: This is the work area where directly edited files are placed
  2. Staging: A staging area is a place where data is temporarily stored, giving developers an opportunity to go back on their mistakes if they add something wrong
  3. Git is a hidden directory where many things are stored, including the index file

Here I create a test.txt file in my workspace:Check the status again:

git status
Copy the code

Running results:Because we just created the file and haven’t done anything yet, we’re still in the Master branch; There are still no commits in the local library.

But watch out for the following:

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.txt

nothing added to commit but untracked files present (use "git add" to track)
Copy the code

Nothing was committed but an untraced file was found. This is the test.txt file that was created earlier.

Since it is not traced, we trace the file with the command:

git add test.txt
Copy the code

After the trace is complete, we perform the view status operation again:

git status
Copy the code

Running results:There are still no commits for the local library, but there is a new file change that can be committed, along with a hint:

(use "git rm --cached <file>..." to unstage)
Copy the code

Git add: git add: git add: git add: git add: git add: git add: git add

 git rm --cached test.txt
Copy the code

After retracting, we recheck the status:Insert the test.txt file into the staging area and execute the command:

git add test.txt
Copy the code

Once added to the staging area, we are ready to commit the contents of the staging area to the local library by executing the following command:

git commit test.txt
Copy the code

After executing this command, the terminal switches to the following interface:Here you need to input a description of this commit, you can write this commit to do what, what functionality, for later maintenance.

The Vim editor is the default Git editor used by the Git terminal during Git installationiEnter edit mode and enter the description of this submission on the first line:iAfter the key the lower left corner will show — insert –, at this point you can start editing.

When you’re done editing, pressescKey to exit edit mode, then press the combination keyShift + :, then input the command:wq, save and exit, and the commit is complete.There’s also some information in there, which I’ll explain later.

At this point we check the status again:This indicates that the staging area is clean, there is nothing to commit, and the workspace has no state changes.

This completes the process of adding, viewing, and committing from the workspace to the staging area with the Git add command, and then committing the staging area to the version area with the Git commit command.

Let’s move on to a scenario where we created an empty file and added some text to the file:At this point we check the status again:A change was not added to the staging area.

no changes added to commit (use "git add" and/or "git commit -a")
Copy the code

You can commit with git add and git commit, or you can commit with git commit because the file has already been traced.

Git commit (Vim, Vim, Vim, Vim, Vim)

Git commit -m "test.txtCopy the code

Submission Results:The result indicates that a file has been modified and 1 line of content has been added.


The tail language

✍ Code writes the world and makes life more interesting. ❤ ️

✍ thousands of rivers and mountains always love, ✍ go again. ❤ ️

✍ code word is not easy, but also hope you heroes support. ❤ ️