day79_10_28git use basis

One. Compared with the git svn.

  git is the version of the controller, the object is to control the project code development.

  With the root timeline can rollback code, changing code version.

  svn version and is characterized by service-user version of separation, when the developer needs to develop this, you need to establish the project in the code repository, developers need to log in every time to go back to the code, and then develop and submit it.

 

 

   In git, the local user version and service release coexist, there are two versions, the first service to interact with the native version on any development equipment, service version before proceeding with the remote server.

 

 

   All aspects of the data can be rolled back by git statement.

 

 

   git branch can also be data, data between each branch is independent, based on the creation of a branch branch timeline is the same.

 

 

 two. git use.

  1. Install

  First, install the official website: https: //git-scm.com/download

  Install git: Choose Use a TrueType font in the selected installation path of the next step in all console windows option. (All font configuration).

  2. Basic commands

  The folder has been initialized to some git repository. Below its file is the file to be submitted.

"" " 
>: Cd internal target folder 
>: git the init 
" ""

  Or can be created git repository

"" " 
>: Cd target directory 
>: git init repository name 
" ""

  In the catalog warehouse terminal - set global users.

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

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

  在仓库目录终端下 - 设置局部用户

"""
>: git config user.name '用户名'
    -- 用户名
>: git config user.email '用户邮箱'
    -- 用户邮箱
    
注:在当前仓库下的config新建用户信息,只能在当前仓库下使用
注:一个仓库有局部用户,优先使用局部用户,没有配置再找全局用户
"""

  查看仓库状态

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

  工作区操作

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

  撤销工作区操作:改、删

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

  工作区内容提交到暂存区

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

  撤销暂存区提交:add的逆运算

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

  提交暂存区内容到版本库

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

  撤销版本库提交:commit的逆运算

"""
回滚暂存区已经提交到版本库的操作:
    查看历史版本:
        >: 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
"""

三。过滤文件。

  在仓库根目录下(与git一个文件夹)创建gitignore,在其中写入不需要的文件,即可过滤文件。

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

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

eg:
a.txt:项目中所有a.txt文件和文件夹都会被过滤
/a.txt:项目中只有根目录下a.txt文件和文件夹会被过滤
/b/a.txt:项目中只有根目录下的b文件夹下的a.txt文件和文件夹会被过滤
"""

四。创建远程gitee仓库

  选择线上仓库

"""
1.注册码云账号并登录:https://gitee.com/
2.创建仓库(课堂截图)
3.本地与服务器仓库建立连接
"""
"""
1)本地配置线上的账号与邮箱
>: git config --global user.name "doctor_owen"
>: git config --global user.email "[email protected]"

2)在本地初始化仓库(git init),并完成项目的初步搭建(项目架构)(一般都是项目负责人完成项目启动)
# 这个过程就是git的基础部分的本地操作

3)采用 https协议 或 ssh协议 与远程git仓库通信提交提交代码(一般都是项目负责人完成)
    i) https协议方式,无需配置,但是每次提交都有验证管理员账号密码
    >: git remote add origin https://gitee.com/doctor_owen/luffy.git  # 配置远程源
    >: git push -u origin master  # 提交本地仓库到远程源
    
    ii) ssh协议,需要配置,配置完成之后就可以正常提交代码
    >: git remote add origin [email protected]:doctor_owen/luffy.git  # 配置远程源
    >: git push -u origin master  # 提交本地仓库到远程源
    
    iii)查看源及源链接信息
    >: git remote
    >: git remote -v
    
    iv)删除源链接
    >: git remote remove 源名字 
    
注:origin远程源的源名,可以自定义;master是分支名,是默认的主分支
"""

  创建仓库

 

   创建仓库后的界面:

 

 

 

 

五。用本地仓库首次初始化远程仓库

  本地仓库与远程仓库建立源连接

前提:本地仓库已经创建且初始化完毕(代码已经提交到本地版本库)

本机命令,添加远程源:git remote add origin ssh@*.git
    采用ssh协议的remote源

  创建电脑的公钥私钥

官网:https://gitee.com/help/articles/4181#article-header0

本机命令,生成公钥:ssh-keygen -t rsa -C "*@*.com"
    邮箱可以任意填写
本机命令,查看公钥:cat ~/.ssh/id_rsa.pub

码云线上添加公钥:项目仓库 => 管理 => 部署公钥管理 => 添加公钥 => 添加个人公钥

  提交本地代码到远程仓库

命令:git push origin master

  添加公钥:

 

  六。remote源操作

"""
1)查看仓库已配置的远程源
>: git remote
>: git remote -v

2)查看remote命令帮助文档
>: git remote -h

3)删除远程源
>: git remote remove 源名
eg: git remote remove origin

4)添加远程源
>: git remote add 源名 源地址
>: git remote add orgin git@*.git
"""

七。多分支开发

  在分支上建立分支时间轴相同。

  每个分支都有独立的空间,随着分支的切换而改变。

"""
1.创建分支
>: git branch 分支名

2.查看分支
>: git branch

3.切换分支
>: git checkout 分支名

4.创建并切换到分支
>: git checkout -b 分支名

5.删除分支
>: git branch -d 分支名

6.查看远程分支
>: git branch -a
"""

 

Guess you like

Origin www.cnblogs.com/LZXlzmmddtm/p/11756413.html