Git story

Git

The concept of Git

First of all we need to know what git is the most fundamental concept of version control, by definition, it can help us control the git version control to write their own code or documentation. To manage different time, different between different collaborators same project version, or a different state.

It says so much, the simplest conclusion, git is a version of the controller software is usually used when the management team to develop the code used.

Git installation

Generally, we use the system only three, namely, windows, linux and mac

  1. windows and mac installation:

    Official website https://git-scm.com/downloads , you can download the corresponding software

  2. linux installation:

    yum install git

Git configuration

After installation is complete, we need to configure git user name and mailbox, you can choose to configure the global or local configuration

Global Users

# 在cmd或者bash的窗口中
git config --global user.name '用户名'
git config --global user.email '用户邮箱'

""" 
上面添加的全局信息是存储在
C:\Users\用户文件夹\.gitconfig 的文件中
如果不想用指令添加全局用户的话,可以直接编辑该文件
"""

Local User Configuration

"""
首先需要在仓库的目录下,右键打开Git Bash Here
指令如下:
"""
git config user.name '用户名'
git config user.email '用户邮箱'
"""
局部配置的优先级大于全局用户
"""

Git commands

In fact, Git supports most Linux native instructions, such as vim, ls, cat, cd and so on.

Git general process divided into two categories, namely uploading and downloading, uploading local data is uploaded to the server, download the server data is downloaded to the client.

Note: In general, before you can upload (push) data, must first be downloaded once from the server (pull), which is operating habits.

Upload process is as follows:

Create a folder (mkdir) -> git initialization (git init) -> submit to buffer (git add filename) -> from the buffer zone to the repository (git commit -m 'information submitted comments') -> From version library submitted to the server (push)

Download is very simple, direct use of pull, or you can clone

"""
1. 查看存在的git仓库
    git status

2. 定义git仓库
    git init (仓库名)  # 不添加仓库名会定义当前文件夹为git仓库

3. 提交至缓存区
    git add README.md
    ~3.缓存区的退回,即add的逆运算
    git reset HEAD . # 撤销所有暂存区的提交
    git reset 文件名  # 撤销某一文件的暂存区的提交

4. 从缓存区到版本库
    git commit -m "注释信息"

5. 从版本库提交至服务端
    在此之前,我们要配置服务端的远程源,这里我们用的是gitee的远程源,远程源一般有两种方式:
    (1)https协议方式
    git remote add origin https://gitee.com/用户名/仓库名
    (2)ssh协议方式
    git remote add origin [email protected]:用户名/仓库名
    
    我们可以用
    git remote -v 来查看当前配置的远程源
    
提交至服务端:
    git push -u 远程库的代号(默认是origin) 本地的版本(默认是master)
比如:
    git push -u origin master
    
6. 从服务端下载至本地,clone和pull还是有区别的
    区别在于,clone是从服务端克隆一个一模一样的版本库到本地,复制的是整个版本库.而pull是从服务端取到一个分支更新到本地.
    
    git pull 远程库的代号(默认是origin) 本地的版本(默认是master)
    git clone 远程库的代号(默认是origin) 本地的版本(默认是master)
比如:
    git pull origin master
    git clone origin master
"""

Guess you like

Origin www.cnblogs.com/Xu-PR/p/11953616.html