Git常用命令-配置类

书接上文Git基础知识

这一期我们来看一下Git命令中的配置仓库类指令。虽然在日常使用Gitee、Github的时候都有优秀的图形化页面,但其实了解配置相关指令能够让大家更加清楚Git的操作流程。在Git操作过程中配置类更是前期使用Git的重中之重。

在Git官方文档中,Git将指令分为高层指令(porcelain)和底层指令(plumbing)。这是由于Git 一开始被设计成供 VCS 使用的工具集而不是一整套对用户友好的VCS,它还包含了许多底层命令。这些命令用于以 UNIX 风格使用或由脚本调用,一般被称为 "plumbing" 命令,其他的更友好的命令则被称为 "porcelain" 命令。

porcelain命令中的常见配置命令:

git init:其中最重要的指令选项个人认为是--bare,这个命令与普通命令区别在于是否建立工作区。语句中增加bare代表创建的是裸仓库,不带工作区作为核心仓库。常见的GitHub、Gitee的仓库均为裸仓库。更多选项请看下方代码块:

概要:
git init [-q | --quiet] [--bare] [--template=<template-directory>]
	  [--separate-git-dir <git-dir>] [--object-format=<format>]
	  [-b <branch-name> | --initial-branch=<branch-name>]
	  [--shared[=<permissions>]] [<directory>]
常用命令:
    git init
    git init --bare

git status:显示工作区与暂存区、暂存区与当前HEAD指针所指向的仓库对象的差异。

概要:
git status [<options>…​] [--] [<pathspec>…​]

常用例子:
    git status
    #显示git status的简短信息
    git status -s 

辅助命令集:

git config:进行Git仓库的设置或者进行Git全局设置

概要:
git config [<file-option>] [type] [--show-origin] [-z|--null] name [value [value_regex]]
git config [<file-option>] [type] --add name value
git config [<file-option>] [type] --replace-all name value [value_regex]
git config [<file-option>] [type] [--show-origin] [-z|--null] --get name [value_regex]
git config [<file-option>] [type] [--show-origin] [-z|--null] --get-all name [value_regex]
git config [<file-option>] [type] [--show-origin] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]
git config [<file-option>] [type] [-z|--null] --get-urlmatch name URL
git config [<file-option>] --unset name [value_regex]
git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --rename-section old_name new_name
git config [<file-option>] --remove-section name
git config [<file-option>] [--show-origin] [-z|--null] [--name-only] -l | --list
git config [<file-option>] --get-color name [default]
git config [<file-option>] --get-colorbool name [stdout-is-tty]
git config [<file-option>] -e | --edit

常用命令:
    #Git账号信息修改
    git config user.name name
    git config user.email email
    git config --unset user.name
    #编辑配置文件/获取信息
    git config --global -e
    git config --get configName
    #显示仓库所有配置
    git config --local --list  # 查看仓库配置
    git config --global --list # 查看用户配置
    git config --system --list # 查看系统配置

git remote:管理需要追踪分支的远程存储库

概要:
git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>…​
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose] show [-n] <name>…​
git remote prune [-n | --dry-run] <name>…​
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)…​]


常见命令:
    git remote -v    #显示对应的远程克隆地址
    git remote add <alias> + git地址 #增加Git远程连接地址
    git remote show <alias>     #查看远程仓库的详细信息
    git remote rename <oldAlias> <newAlias>    #修改远程仓库别名
    git remote rm <alias>    #移除远程仓库

git version:查看当前Git仓库的版本

概要:
git version [--build-options]

gitweb:Git web界面。使用gitweb,需要从Git文件夹下运行git-instaweb。配置并启动Web服务器,将web容器启动后指向gitweb

概要:
git instaweb [--local] [--httpd=<httpd>] [--port=<port>]
               [--browser=<browser>]
git instaweb [--start] [--stop] [--restart]

plumbing命令中的常见配置命令:

git-ls-remote:显示远程存储库中可用的引用以及关联的提交ID

概要:
git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]
              [-q | --quiet] [--exit-code] [--get-url]
              [--symref] [<repository> [<refs>…​]]

常用命令:
    git ls-remote --heads url    #查看远程仓库所有分支

git-credential:检索并存储用户凭证

git-credential-cache:临时将密码存储在内存中

git-credential-store:将证书存储在磁盘上

下面概要为Git凭证存储的指令:

概要:
git credential <fill|approve|reject>
git config credential.helper 'cache [options]'
git config credential.helper 'store [options]'

这里提醒一点:可能有的小伙伴发现git push的时候不需要输入账号密码就可以提交代码了。但这其实是得益于Git的凭证存储机制。Git可以通过ssh或者http来访问远端,如果使用了ssh方式,设置了RSA密钥登陆且不需要密码口令,那么使用时候就不需要账号密码。但如果使用了http方式登陆的话,经过Git凭证存储机制也可以完成不需要密钥的账号登录。

git-hook:执行Git中的钩子指令。Git 有两组挂钩:客户端和服务器端,客户端挂钩用于客户端的操作,如提交和合并。服务器端挂钩用于 Git 服务器端的操作,如接收被推送的提交。挂钩被存储在Git目录下的hooks子目录中,Git默认会放置一些脚本样本在这个目录中。在Git 1.6版本之后,这些样本名都是以.sample结尾,因此必须重新命名。在Git 1.6版本之前,这些样本名都可直接使用,但不是可执行文件。脚本激活方式:把一个正确命名且可执行的文件放入Git 目录下的hooks子目录中,就可以激活该挂钩脚本,之后就会被Git在操作相关命令的时候自动调用。

git hook run [--ignore-missing] <hook-name> [-- <hook-args>]

本期就到这里,下一篇讲一讲Git常用命令-外部系统交互指令

猜你喜欢

转载自blog.csdn.net/weixin_42505381/article/details/128563230
今日推荐