Git learning summary (1)

Recommend a learning address to everyone: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

 

1. Get to know Git

    Git is a distributed version control system, so what is the difference between it and a centralized version control system (CVS, SVN, etc.)?

Centralized : The version library is centrally stored on the central server and must be connected to the Internet to work

Distributed : There is no central server (actually there is a central server, just for exchanging modified code), each client is a complete repository. Security is higher because everyone is independent.

 

2. Git installation

    I am learning on Windows and the installation files can be found in the previous learning URL.

After installation, you need to perform a configuration work (under Git Bash):

git config --global user.name "username"

git config --global user.email "your own mailbox"

 

3. Git usage

In the absence of a remote repository, we can create a repository on our own computer. The process is very simple:

1. Select an existing directory or create a desired directory under Git Bash through the command: mkdir directory name;

2. cd to the directory we planned and use the command: git init, so that this directory becomes a repository that Git can manage, and verify whether the operation is successful: ls -ah can see a hidden file. git

 

The following is a list of commonly used commands when using Git:

git add : When a new file is added to the repository, we need to execute this command to submit the file to the Git staging area stage based on the workspace

git commit -m "remarks" : commit files to the repository

git status : Check the current status of the warehouse at all times

git diff : view the content of specific changes

git reset --hard HEAD^ : go back to the previous version

 

Undo changes:

git checkout --reset (the modification of the workspace has not executed git add)

git reset HEAD file (the modification of the workspace has been git add)

 

Delete the files in the repository: git rm file

 

4. Remote warehouse (GitHub)

Since Git is a distributed version control system, how does it achieve distribution? Through a remote repository, it is not divided into different machines, and each machine is an independent version library.

 

The local repository and GitHub repository transmission is encrypted through SSH, which needs to be set:

ssh-keygen -t rsa -C "mailbox set earlier"

 

So how does the local warehouse associate with the remote warehouse?

git remote add origin remote warehouse address

 

Push the local content to the remote warehouse: git push -u origin master (for the first time, you can use git push directly later)

 

Clone from remote repository to local: git clone remote repository address xxx .git

 

Get the latest content of the remote repository and merge it into the local repository: git pull

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327038024&siteId=291194637