Git study notes (basic version)

I mainly learned Git through the official documentation.
Link to GIt official website: https://git-scm.com/book/zh/v2.
Git official documentation has multiple national language versions, we can choose Simplified Chinese version.

Learning these questions can support the daily use of Git.

1. What is Git?

Git is a distributed version control system (Distributed Version Control System, referred to as DVCS).
The client does not only extract the latest version of the file snapshot, but completely mirrors the code warehouse, including the complete history.

Git has three states, and your files may be in one of them:
committed, modified, and staged .
Modified means that the file has been modified but not yet saved to the database.
Staged means that the current version of a modified file is marked for inclusion in the next committed snapshot.
Committed means that the data has been safely saved in the local database.

This will give our Git project three stages: the workspace, the staging area, and the Git directory.
The basic Git workflow is as follows:
(1) Modify files in the workspace.
(2) Selectively store the changes you want to submit next time, so that only the changed part will be added to the temporary storage area.
(3) Submit the update, find the files in the temporary storage area, and permanently store the snapshot in the Git directory.

2. Install Git on Windows

Download the installation package for the official version, https://git-scm.com/download/win.
According to the system version of the computer, select the corresponding version 32 and 64.
insert image description here
After the download and installation are complete, right-click the mouse. There will be GUI mode and command line mode.
insert image description here

3. How to operate Git and common commands of Git?

(1) Add user information
After installing Git, the first thing to do is to set your username and email address. This is important because every Git commit uses this information, and it's written to every commit you make, immutable:

$ git config --global user.name "John xxxx"
$ git config --global user.email [email protected]

(2) Check configuration information
After adding user information, you can check configuration information

$ git config --list

(3) Establish a Git warehouse
There are usually two ways to obtain a Git project warehouse:

  • Convert a local directory that has not yet been versioned into a Git repository;
  • Clone an existing Git repository from another server.

Initialize the repository in an existing directory
On Windows, change into the my_project directory:

$ cd /c/user/my_project

Then execute git init, which will create a subdirectory named .git, which contains all the necessary files in the Git repository you initialized. These files are the backbone of the Git repository.

$ git init

Cloning an existing repository
The command to clone a repository is git clone . For example, to clone Git's link library libgit2, you can use the following command:

$ git clone https://github.com/libgit2/libgit2

(4) Check the current file status

$ git status

(5) Tracking and adding new files
Use the command git add to start tracking a file. So, to follow the README file, run:

$ git add README

(6) Submit update
Before submitting for the first time, use git status to see if all the files you need have been temporarily stored, and then run the commit command git commit. In addition, you can also add the -m option after the commit command to put the commit information and the command on the same line, as shown below:

$ git commit -m "本次修复了xxxbug"

(7) View submission history

$ git log

Guess you like

Origin blog.csdn.net/daxiangaifashi/article/details/117736302