Detailed explanation of Git - installation, use, construction, IDEA integration

Git

看目录,篇幅挺长,越往后面越重要

Table of contents
1. What is git?
2. Why use Git?
3. Version control tools
4. git download, installation and environment configuration
5. Basic git commands
6. git project construction
7. How to create a remote warehouse? The difference between git, gitlab, github and gitee
8. Idea integrates Git

1. What is Git?

  • Git is a distributed source code management tool (version control tool)
  • With Git, every time you commit or save the state of your project, Git basically records what all the files looked like at that time and stores a reference to that snapshot
    Insert image description here

2. Why use Git?

  • When you need to do a big project, file management is undoubtedly a very huge task, because you need to constantly modify and update the file content, and you may also need to keep the old version to ensure that it can be restored , so you need to back up multiple versions of the file. .

  • And in most cases, a project needs to be jointly maintained by most people . In this case, it is also very troublesome to merge the modified content between different people . In this case, you can use git to easily solve these problems.


3. Version control tools

Mainstream version controllers include the following:

  • Git: distributed version control (most popular)

  • SVN (Subversion): Centralized version control (will be used)

  • CVS(Concurrent Versions System)

  • VSS(Micorosoft Visual SourceSafe)

  • TFS(Team Foundation Server)

  • Visual Studio Online

The difference between git and svn

Currently the most popular version control framework is git, but there are also many using svn;

Insert image description here

git

advantage:
  • Suitable for distributed development, emphasizing individuals.

  • The public server pressure and data volume will not be too large.

  • Fast and flexible.

  • Conflicts between any two developers can be easily resolved.

  • Work offline.

shortcoming:
  • There is little information (at least there is very little information in Chinese).

  • The learning cycle is relatively long.

  • Not in line with conventional thinking.

  • Code confidentiality is poor. Once the developer clones the entire library, all code and version information can be fully disclosed.

svn

advantage:
  • Centralized management, the management method is configured on the server, and the client only needs to submit it synchronously. It is easy to use, simple to operate, and easy to get started.

  • Control access rights uniformly on the server side and utilize code security management.

  • All codes are subject to the server side, and the code consistency is high.

shortcoming:
  • All operations need to be synchronized through the server, which will lead to relatively high server performance requirements. If the server is down, you cannot submit the code.

  • Branch management is not flexible. The svn branch is a complete directory, and this directory has complete actual files. These operations are synchronized on the server.

  • It is not a localized operation. If you want to delete a branch, you also need to delete the remote branch, which will cause everyone to synchronize.

  • An Internet connection is required. If you cannot connect to the server, you cannot submit the code.


4. git download, installation and environment configuration

git official website download

1. Click Downloads to select your operating system and select 32-bit or 64-bit

Insert image description here

如果下载慢,那就选用国内镜像下载,这里提供了[阿里镜像地址](https://registry.npmmirror.com/binary.html?path=git-for-windows/),选择比较稳定的版本,自己运用的系统版本

2. For example, if I choose this, click download

Insert image description here
3. The next step is the installation process. I won’t talk nonsense here. It’s very simple steps. Just read the blogger’s installation blog post.

Git download and installation tutorial

打开git除了该博主说的桌面快捷键外,右击鼠标,选择 “Git Bash Here” 也可以;另外环境配置也可能已经自动给配置上了,配置上的话就不用再配置了

4. Open git. In fact, the commands to operate files in the git text box are Linux commands, as follows:

Insert image description here

Insert image description here


*5. Basic git commands

View git configuration

git config -l

Insert image description here
So where is this configuration file located locally?

git安装目录/etc/gitconfig 文件

Insert image description here

View git local system configuration

git config --system --list

Insert image description here

Similarly, where is this local system configuration file located?

c盘/用户/用户名下的 “.gitconfig”文件中

Insert image description here

**这个本地配置需要自己配置。以后提交代码之类的会用得着,怎么配置呢?如下

Insert image description here
Then open the local configuration file and find that the information has been written

View the current user configuration of git

--global全局
git config --global --list

Clone code

git clone 远程地址

View local branch

git branch

View remote branch

git branch -r

View all branches

git branch  -a

switch branch

git checkout 分支名

Create a branch

git  branch 分支名

Create new branch and switch

git checkout -b 分支名

Check the branch status

git status

View log

git log

git creates local branch from remote branch

git checkout -b 本地分支名 origin/远程分支名

git adds content to cache

git add .

git commits content to local

git commit 

git updates warehouse content

git pull  origin master

git commits content to the remote repository

git push origin master   #-f强推

git Get the latest changes

git fetch origin

illustrate

The most commonly used commands on projects are add, commit, push, pull, and checkout.

Working Directory : workspace, where project code is usually stored

Stage (index) : used to temporarily store changed files

Repostory : The warehouse area (or local warehouse) is a safe place to store data. All versions of data you submitted are here; HEAD points to the latest version put into the warehouse.

Remote : Remote warehouse, a server that hosts code, can be a simple computer in your project team for remote data exchange of three local areas. To be precise, it should be the version pointed to by HEAD in the git warehouse.

Insert image description here


6. Git project construction

Insert image description here
git安装上了,命令也学习了,那么项目如何搭建呢?

method one:

1. First create an empty folder, as shown below, it is currently an empty folder

Insert image description here
2. Right-click "Git Bash Here" and enter "git init", which is to initialize the project. A .git hidden folder appears in the file. If you don't find it, click to view it - check "Hidden Files"

Insert image description here

Method two:

Clone remote project directly

git clone [远程项目url]

7. How to create a remote warehouse?

这里我们先聊一下Git,Gitee,GitLab,GitHub是个什么玩意?

Let’s look at the definition first:

  • Git distributed version control system

  • Gitee code cloud, a domestic remote warehouse, which is an online code hosting tool, your project can be pushed here remotely; Gitee official website

  • GitLab is an open source project for warehouse management systems. It uses Git as a code management tool and builds a web service based on it. Generally used to build private servers in enterprises, you need to set up your own environment GitLab official website

  • GitHub is also an online code hosting warehouse, a foreign remote warehouse; after all, it is foreign, and it is very slow to open GitHub official website

——So let’s talk about Gitee here.

  • 1. The first thing is to modify the basic information after registering and logging in.

Insert image description here

  • 2. Generate the public key, that is, you do not need to enter the username and password every time when pushing the local code to the remote warehouse; I already have it here;

Insert image description here

Right-click "Git Bash Here" in any directory, enter the following content, and press Enter

--rsa是加密算法方式
 “ssh-keygen -t rsa”

The public key has been generated at this time, and the public key file is in the local directory c drive/user/username/.ssh/id_rsa.pub
Insert image description here

Open the file and paste all its contents into the following input box. Click OK to add

Insert image description here

  • 3. Create a warehouse and change the warehouse to public. You need to modify it after creation.

Insert image description here

  • 4. The warehouse is now built, and then the remote warehouse is cloned locally.

Create a folder and enter the following

git clone [远程仓库url]

Insert image description here
At this time, the local file and the remote file are the same

  • 5. Test the command

Right-click in the cloned folder to open git and run the following command

--查看状态
git status

--创建一个文件
touch hello.html

--查看状态,会发现有个红色文件,表示有新文件没有add
git status

--添加
git add .

--查看状态,发现文件变绿,表示有没提交的文件
git status

--提交文件到本地仓库,这里要加-m 并且后面说明提交信息
git commit -m “new file hello.html”

--查看状态,发现提示没有要提交的文件了
git status

--推送到远程仓库
git push origin master

--这个时候你会发现你的远程仓库已经有了你推送的文件hello.html


*8. IDEA integrates Git

1. Find Git in Version Control, fill in your own Git path, and click OK
Insert image description here

2. Or directly copy and paste the .git file into this project, you will find the Git button appears in the upper right corner of the idea, and the submission history is displayed in the lower right corner.

Insert image description here

You can do everything directly with idea; you may have to enter your username and password when pushing.

Insert image description here


Reference video

Hope it helps you

~感谢您的光临~

Insert image description here

Guess you like

Origin blog.csdn.net/m0_50762431/article/details/130713691