Git的基本操作| 8月更文挑战

478 阅读6分钟

欢迎关注公众号:卢卡多多

这是我参与8月更文挑战的第1天,活动详情查看:8月更文挑战

Git的开篇

Git可能是我们每天最常用的工具了,我们每天用于代码的更新,提交,版本控制,分支切换等功能,为我们的开发提供可特别大的遍历。但是感觉我们对于Git还是停留在Git commit ,Git push的阶段,所以,为初次研发小伙伴,准备系统的出一篇文章关于Git技术文章;

工余力其实,必先利其器----GIt

Git的优势


  • 分布式的版本控制工具
  • 良好的存储能力,性能
  • 支持离线操作
  • 开源的
  • 很容易备份
  • 很容易定制工作流程

Git的官网信息

下载地址:

git-scm.com/

检查版本

git  --version

Git的简单配置:

配置基本信息

  git   config --global  user.name 'lucas'
  git   config --global  user.email 'lucas@163.com'

开始配置一:查看基础的配置环境:

     查看基础的配置环境:
  git  config
  
  
  
  C:\Users\web>git config
usage: git config [<options>]

Config file location
    --global              use global config file          当前全局配置的文件
    --system              use system config file          当前系统配置的文件
    --local               use repository config file      当前仓库配置的文件
    --worktree            use per-worktree config file
    -f, --file <file>     use given config file
    --blob <blob-id>      read config from given blob object

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --get-urlmatch        get value specific for the URL: section[.var] URL
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 add a new variable: name value
    --unset               remove a variable: name [value-regex]
    --unset-all           remove all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            open an editor
    --get-color           find the color configured: slot [default]
    --get-colorbool       find the color setting: slot [stdout-is-tty]

Type
    -t, --type <>         value is given this type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)
    --expiry-date         value is an expiry date

Other
    -z, --null            terminate values with NUL byte
    --name-only           show variable names only
    --includes            respect include directives on lookup
    --show-origin         show origin of config (file, standard input, blob, command line)
    --default <value>     with --get, use default value when missing entry

获取当前所有配置的信息:

 git  config --list 

仓库的基础配置

git  config --list --global
当前全局仓库的配置列表

git  config  --list  --system

git  config  --list  --local

git的配置用户

 git  config  --global  user.name 'lucas'
  //配置全局的用户名  (user.name加入空格)
  
  git config   --global  user.email 'lucas@163.com'
  //配置全局的邮件名 

操作2

基于我们直接安装了git ,并且是将git的用户和基础的配置已经成功, 开始建立git 配置的仓库,(代码管理的文件路径);

1.开始建立Git的代码仓库:

自己已经有代码--直接交给Git进行管理

cd   项目所在文件夹
git  init

特别说明: 因为之前的配置是对于GIt的全局的配置,但是对于特定的项目仓库,一般建议是来本地的配置


git  config --local  user.name 'weblucas'

git config  --global  user.email '2343454422@qq.com'


##查看当前仓库配置的列表
 git  config --list  --local

这个仓库已经可以正常工作

2.测试文件加载到git ,如何管理

比如说我创建一个文件readme ,若是直接

git  commit  -m'提交这次注释的内容'
但是会出错误,表示git 还没有管理新文件readme


解决方案:
    git   add  readme       '添加新文件到git管理'
    
    git     status           '查看git的状态'

在 分支 master 上 已经添加到新文件到暂存区域

其实有个命令是

git  log 
//看到详细的信息关于这次提交的

特别要点: 但是对于基础的local或者是global的优先级详解:

  • 当前仓库未设置 ,本地的local的设置--会采用的是global的设置
  • 要是本地设置了local的配置,优先选择local的配置作为本仓库的设置

情形二

没有代码,需要直接建立仓库来完成管理

git的暂存区域

注意的点:

暂存区存在的意义:

  • 工作目录的调整,新方案的改变---可以提交合并,也可以回退版本
  • 起到对代码灵活控制的一个作用

1.开始文件的提交和暂存

第一步开始复制文件index;

表示复制过后 查看git 状态

 git  status

 git   add  文件名

 git   status

 开始提交到远程目录
git   commit -m '提交的注释文件'

但是在其中加入暂存区 git add

//一般会直接确定文件的名字
 git  add  index.html
 
 但是多个文件 可以直接空格 接着写
 
 git  add  -u
 表示可以直接提交改变git已经管理文件的改变
 

2.开始文件的重命名:

改变文件名的一步操作

git  mv  源文件名  现在改变文件的名字

然后直接git  commit -m'表示一个改变文件名字的提交'

如果是基础的操作需要三步进行操作:

git  reset   --hard

'表示将工作目录,暂存区所有的变更都删除',也就是说本地的变更会删除
但是不会影响远程的路径;

比如 git log ,提交的之前的数据和节点都存在;

3.利用Git log 查看版本演变历史

一般使用的是 git log来获取所有的提交历史 但是特别的多,可以分类

 git  log --online            '显示一行的git log提交的历史'

git  log  -n2 
git  log - n3
'表示显示最近提交的2次或者三次的历史'

 git branch -v
//当前仓库有多少分支
git branch -av

git  log --all
表示所有分支的所有提交,

git  log  
表示当前分支的提交
$ git  log
commit 1b5e86d67c5ab09c0255aa37a847859fc948da12 (HEAD -> master)
Author: web <2435034422@qq.com>
Date:   Sun Apr 12 23:43:09 2020 +0800

    index+logo

commit d9267293d93542109e094dbce3a76d7a12c0bbfc
Author: mwbstart <mwbstart@163.com>
Date:   Fri Apr 3 23:15:14 2020 +0800

    'zookeeper和consul作为服务注册中心'

commit 56f730e3c78d54ff1674bfd73f2229bf6c8b65ea
Author: mwbstart <mwbstart@163.com>
Date:   Thu Apr 2 23:24:48 2020 +0800

      SpringCloud的Eureka完结(28)

web@DESKTOP-DDH479E MINGW64 /d/IDEA2019.3.3WORKSPACE/springCloud2020 (master)
$ git log --all
commit 1b5e86d67c5ab09c0255aa37a847859fc948da12 (HEAD -> master)
Author: web <2435034422@qq.com>
Date:   Sun Apr 12 23:43:09 2020 +0800

    index+logo

commit d9267293d93542109e094dbce3a76d7a12c0bbfc
Author: mwbstart <mwbstart@163.com>
Date:   Fri Apr 3 23:15:14 2020 +0800

    'zookeeper和consul作为服务注册中心'

commit 5d6448cafb497014aa3ef240662581fb2e227843 (dev)
Author: mwbstart <mwbstart@163.com>
Date:   Thu Apr 2 23:47:13 2020 +0800

    提交Eureka的禁止自我保护

commit 4359859c2a4c4f75ea19860e24255a74aae6ddb1
Author: mwbstart <mwbstart@163.com>
Date:   Thu Apr 2 23:29:39 2020 +0800

    'springCloud2020'

commit 56f730e3c78d54ff1674bfd73f2229bf6c8b65ea
Author: mwbstart <mwbstart@163.com>
Date:   Thu Apr 2 23:24:48 2020 +0800

      SpringCloud的Eureka完结(28)

web@DESKTOP-DDH479E MINGW64 /d/IDEA2019.3.3WORKSPACE/springCloud2020 (master)

git 表示历史的图形化,或者说是分支的演变过程
 git  log --all --oneline --graph

开启Git 自带的图形化版本演变历史

$ git help --web log
//浏览器直接变成一个帮助文件

自己创建之后

new view--> ALL