Git version control

Version control: Git

# 达到多人协同开发的目的

installation

"""
1.下载对应版本:https://git-scm.com/download
2.安装git:在选取安装路径的下一步选取 Use a TrueType font in all console windows 选项
        -- 安装成功后桌面右键可以看到git菜单
"""

work flow chart

Build local git repository

The existing folder as a git repository

"""
>: cd 目标文件夹内部
>: git init
"""

Create a git repository in the specified directory

"""
>: cd 目标目录
>: git init 仓库名
"""

User information configuration operation git

Current Warehouse: Local

"""
>: git config user.name '用户名'
    -- 用户名
>: git config user.email '用户邮箱'
    -- 用户邮箱
    
注:在当前仓库下的config新建用户信息,只能在当前仓库下使用
"""

All warehouses: Global

"""
>: git config --global user.name '用户名'
>: git config --global user.email '用户邮箱'

注:在全局文件 C:\Users\用户文件夹\.gitconfig新建用户信息,在所有仓库下都可以使用
"""

Common commands

Check warehouse status

"""
# 当仓库中有文件增加、删除、修改,都可以在仓库状态中查看
>: git status  
    -- 查看仓库状态
>: git status -s  
    -- 查看仓库状态的简约显示
"""

Workspace operation

# 通过任何方式完成的文件删与改
# 空文件夹不会被git记录

Workspace undo operations: change, delete

"""
>: git checkout .
    -- 撤销所有暂存区的提交
>: git checkout 文件名
    -- 撤销某一文件的暂存区提交
"""

Workspace content submitted to the staging area

"""
>: git add .  
    -- 添加项目中所有文件
>: git add 文件名  
    -- 添加指定文件
"""

Undo staging area submitted: add inverse operation

"""
>: git reset HEAD .
    -- 撤销所有暂存区的提交
>: git reset 文件名
    -- 撤销某一文件的暂存区提交
"""

Submitted to the staging area to the content repository

# git commit -m "版本描述信息"

Revocation repository submit: commit inverse operation

"""
回滚暂存区已经提交到版本库的操作:
    查看历史版本:
        >: git log
        >: git reflog
    查看时间点之前|之后的日志:
        >: git log --after 2018-6-1
        >: git log --before 2018-6-1
        >: git reflog --after 2018-6-1
        >: git reflog --before 2018-6-1
    查看指定开发者日志
        >: git log --author author_name
        >: git reflog --author author_name
    回滚到指定版本:
        回滚到上一个版本:
            >: git reset --hard HEAD^
            >: git reset --hard HEAD~1
        回滚到上三个版本:
            >: git reset --hard HEAD^^^
            >: git reset --hard HEAD~3
        回滚到指定版本号的版本:
            >: git reset --hard 版本号
            >: eg: git reset --hard 35cb292
"""

Filter file

# .gitignore 文件
# 1)在仓库根目录下创建该文件
# 2)文件与文件夹均可以被过滤
# 3)文件过滤语法

""" 过滤文件内容
文件或文件夹名:代表所有目录下的文件或文件夹都被过滤
/文件或文件夹名:代表仓库根目录下的文件或文件夹被过滤
目录/文件或文件夹名:代表特定目录下的文件或文件夹被过滤
"""

git vs svn

# 1、git是分布式的,每一个客户端均可以作为服务器为其他客户端提供代码
# 2、git有强大的分支管理机制,可以在子分支上开发,将最终的成果同步到主分支即可

Guess you like

Origin www.cnblogs.com/fuwei8086/p/11361232.html
Recommended