[GIT]版本控制工具

2023-09-15 22:53:13

Git 是分布式的版本控制工具

Git 的命令

可以直接在终端输入 git+回车,此时会出现提示信息

此时查看提示信息,列出了常用的 git 的可执行命令以及简介

usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone             Clone a repository into a new directory
   init              Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add               Add file contents to the index
   mv                Move or rename a file, a directory, or a symlink
   restore           Restore working tree files
   rm                Remove files from the working tree and from the index
   sparse-checkout   Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)
   bisect            Use binary search to find the commit that introduced a bug
   diff              Show changes between commits, commit and working tree, etc
   grep              Print lines matching a pattern
   log               Show commit logs
   show              Show various types of objects
   status            Show the working tree status

grow, mark and tweak your common history
   branch            List, create, or delete branches
   commit            Record changes to the repository
   merge             Join two or more development histories together
   rebase            Reapply commits on top of another base tip
   reset             Reset current HEAD to the specified state
   switch            Switch branches
   tag               Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch             Download objects and refs from another repository
   pull              Fetch from and integrate with another repository or a local branch
   push              Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

Git 的配置信息

查看现有 Git 配置信息

git config --list

输出

diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
user.name=xxxx
user.email=****@xx.xx****
credential.helper=store
http.sslverify=false

设置 Git 配置信息

用户信息配置

  • user.name:提交的用户名称
  • user.email:提交的用户邮件
  • global: global 设置全局配置,否则设定的为当前项目的配置
git config [--global] user.name xxxx
git config [--global] user.email xxxx

文本编辑器配置

一般 Git 使用的文本编辑器是 Vi 或者 Vim,也可设置为 Emacs

git config [--global] core.editor emacs

差异分析工具配置

解决合并冲突时使用的差异分析工具,git 的差异分析工具选项包括:
kdiff3,tkdiff,meld,xxdiff,emerge,vimdiff,gvimdiff,ecmerge,和 opendiff 等合并工具的输出信息

git config [--global] merge.tool vimdiff

编辑 Git 配置文件

git config -e [--global]

输出:

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/******/xxxx.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

Git 仓库操作

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tQwoB3Mr-1682055699588)(2023-04-21-13-33-00.png)]

  • workspace : 工作区
  • staging area : 暂存区/缓存区
  • local repository : 版本库或本地仓库
  • remote repository : 远程仓库

初始化 Git 仓库

git init [path]// 初始化 [指定路径] git 仓库
git add *.c //新增.c结尾的文件为版本控制范围
git add README //新增README文件为版本控制范围
git commit -m '提交说明'

克隆 Git 仓库

git clone <repo> [<directory>]
  • repo: git 仓库
  • directory: 本地目录

Git 分支仓库创建

命令说明
git branch列出所有分支
git branch (branchname)创建分支命令
git checkout (branchname)切换分支命令
git merge [alias]/[branch]合并分支命令
git branch -d (branchname)删除分支命令

当你切换分支的时候,Git 会用该分支的最后提交的快照替换你的工作目录的内容, 所以多个分支不需要多个目录

Git 远程仓库命令

命令说明
git remote查看用户远程库
git remote add [shortname] [url]添加远程仓库
git remote rm [别名]删除远程仓库
git fetch从远程库获取代码
git pull下载远程库代码并合并
git push [alias]/[branch]推送分支数据到远程仓库

Git 提交历史

命令说明
git log查看历史提交记录
git blame [file]以列表形式查看指定文件的历史修改记录

git log [attr]:

  • –oneline : 提交记录简洁版本
  • –graph : 提交历史拓扑
  • –reverse : 逆向显示提交历史
  • –author : 查找指定用户的提交日志
  • –since : 查找指定日期的提交日志
  • –before : 查找指定日期前的提交日志
  • –until : 查找到指定日期的提交日志
  • –after : 查找指定日期后的提交日志
  • –no-merges : 隐藏合并提交
  • –decorate : 查看日志标签
git log --before={3.weeks.ago}
git log --after={2010-04-18}

Git 标签

添加标签

希望记住特别的提交快照,可以使用 git tag 打上标签

git tag -a <tagname> [-m "runoob.com标签"] [commitId]
  • [-a] 创建一个带注解的标签,记录添加标签的原因,GIT 打开编辑器写注释
  • [commitId] 之前忘记添加标签时,可以通过 commitId 指定之前提交的版本添加注释

查看已有标签

git tag

删除标签

git tag -d [tagname]

查看标签版本的修改内容

git show [tagname]

其它操作

命令说明
git add .添加文件到暂存区
git commit将暂存区内容添加到版本库或本地仓库中
git status查看仓库当前状态
git diff比较文件的不同,即暂存区和工作区的差异。
git reset回退版本
git rm将文件从暂存区和工作区中删除
git mv移动或重命名工作区文件
更多推荐

2022年统计用区划代码表SQL 第二部分02

行政区划代码为国家公布的六位县级以上行政区划代码行政区编码的用途:APP里做城市级联选择根据身份证前六位获取用户所在城市区县370786昌邑市370800济宁市370811任城区370812兖州区百度高德等接口通常都会返回adcode字段(行政区编码)根据行政区编码可以查询天气数据例如请求天气API接口,传参adcod

java面试题

java面试题java基础面试题1.hashcode和equals如何使用2.==和equals的区别3.重写和重载的区别4.代理的几种实现方式5.String、StringBuffer、StringBuilder区别及使用场景6.怎样声明一个类不会被继承,什么场景下会用7.自定义异常在生产中如何应用8.java面向对

GaussDB(DWS)云原生数仓技术解析:湖仓一体,体验与大数据互联互通

文章目录前言一、关于数据仓库需求场景分类二、数据仓库线下部署场景2.1、线下部署场景介绍及优劣势说明2.2、线下部署场景对应的客户需求三、数据仓库公有云部署场景3.1、公有云部署场景介绍及优劣势说明3.2、公有云部署场景对应的客户需求四、为何重视数据共享(含湖仓一体)?4.1、传统数据共享业务场景4.2、数据共享(含湖

Flutter插件的制作和发布

Flutter制作插件有两种方式(以下以android和ios为例):目录1.直接在主工程下的android和ios项目内写插件代码:2.创建独立FlutterPlugin项目,制作各端插件后,再引入项目:1.创建FlutterPlugin:2.FlutterPlugin创建完成:3.使用androidstudio打开

Mybatis框架学习

什么是mybatis?mybatis是一款用于持久层的、轻量级的半自动化ORM框架,封装了所有jdbc操作以及设置查询参数和获取结果集的操作,支持自定义sql、存储过程和高级映射mybatis用来干什么?用于处理java和数据库的交互使用mybatis的好处与JDBC相比,减少了50%以上的代码量。MyBatis灵活,

从零开始的PICO开发教程(4)-- VR世界 射线传送、旋转和移动

从零开始的PICO开发教程(4)--VR世界射线传送、旋转和移动文章目录从零开始的PICO开发教程(4)--VR世界射线传送、旋转和移动一、前言1、大纲二、VR射线移动功能实现与解析1、区域传送(1)新建XROrigin(2)新建一个用于传送的地面(3)将XROrigin设置为可传送的Provider并赋值给可传送地面

外包“混”了2年,我只认真做了5件事,如今顺利拿到字节 Offer...

前言是的,我一家外包公司工作了整整两年时间,在入职这家公司前,也就是两年前,我就开始规划了我自己的人生,所以在两年时间里,我并未懈怠。现如今,我已经跳槽到了字节,顺利拿下offer。自己的情况很普通,本科文凭,没有背景,分享这次我的经历,想鼓励和我同样起点的人字节面试题(技术部分)1.linux基本语句2.http/h

Unity SteamVR 开发教程:SteamVR Input 输入系统(2.x 以上版本)

文章目录📕前言📕教程说明📕导入SteamVR插件📕SteamVRInput窗口⭐action.json文件⭐窗口面板⭐SteamVR_Input目录📕SteamVR动作的类型⭐Boolean⭐Single⭐Vector2⭐Vector3⭐Pose⭐Skeleton⭐Vibration📕动作和按键绑定窗口Bi

使用 YCSB 和 PE 进行 HBase 性能压力测试

HBase主要性能压力测试有两个,一个是HBase自带的PE,另一个是YCSB,先简单说一个两者的区别。PE是HBase自带的工具,开箱即用,使用起来非常简单,但是PE只能按单个线程统计压测结果,不能汇总整体压测数据,更重要的是,PE没有YCSB的预设模板(Workload)功能,测试场景单一,相较而言,YCSB要强大

51单片机项目(12)——基于51单片机的智能台灯设计

本次设计的功能如下:首先使用PCF8591芯片,实现了ADDA转换,AD采集的是光敏电阻的信息,光照强度越强,电压越小,AD采集到的数值越小。同时将AD采集的数字量作为DA输出时的输入量,模拟输出端接了一个LED,用以指示输出模拟量的大小,输出模拟量越大,LED就越亮。所以这一部分的工作过程如下:当光照强度太弱时,AD

【C++】构造函数初始化列表 ② ( 构造函数 为 初始化列表 传递参数 | 类嵌套情况下 的 构造函数 / 析构函数 执行顺序 )

文章目录一、构造函数为初始化列表传递参数1、构造函数参数传递2、代码示例-构造函数参数传递二、类嵌套情况下的构造函数/析构函数执行顺序1、构造函数/析构函数执行顺序2、代码示例-构造函数执行顺序一、构造函数为初始化列表传递参数1、构造函数参数传递构造函数初始化列表还可以使用构造函数中的参数;借助构造函数中的参数列表,可

热文推荐