1.配置仓库
1.1 git init
cd workspace/git-test
git init
等价于git init workspace/git-test
对同一个repo git init多次不影响
创建裸仓库(Bare repo),没有.git目录,不能编辑和commit,用于成为git push、git pull的remote repo
// 这个repo的目录可以不预先创建
git init --bare <repo>
裸仓库只用作存储目的,没有被修改的风险,developer的local repo应该是非bare的repo,这样才可以update,commit
git init <repo> --template=<template_dir>,template怎么用的,和git hook?
复制template目录的内容到新创建的repo的.git目录
分离项目文件和.git目录,如果.git太大,可以将其移到高性能磁盘server上。
git init <repo> --separate-git-dir=<target-dir>
1.2 git clone
Git clone <repo-path>
Repo-path可以是remote-repo或者本地repo,
Git clone会默认将clone的remote repo命令为origin并创建和该remote repo的连接,用于后续的交互(git push、git pull),查看.git/refs/remote目录验证
【指定clone到本地的repo名字】
git clone <remote-repo-url> <local-name>
【指定特定的tag】
git clone --branch <tag-name> <repo> [<local-repo-name>]:下载从最开始直到指定tag的commit的代码,且分支切换到对应tag name的分支
【shadow clone】
用于指定只clone最近的几个commit,避免commit history太多导致硬盘空间占用太多
git clone --depth=<depth-number> <remote-repo> [<local-repo-name>]
下载下来的分支是由remote repo的HEA的指定。
【指定下载的branch】
默认clone的分支是由remote repo的HEAD指向决定
Git clone --branch <specified-branch> <remote-repo> [<local-repo-name>]
注意:指定tag也会默认指定tag对应的branch
可以节省时间:如果你要查看某个repo的指定branc而不是master分支的代码。
【本地创建不可编辑的托管remote repo】
Git clone --bare <remote-repo> [<local-repo-name>]
没有.git目录
【本地创建remote reop的mirror 托管repo】
类似--bare,也不可标记,没有.git目录,但是有remote repo的tracking info,可以通过git remote update更新得到cloned remote repo的new branch、commit等信息
【clone时加上template】
会把template里的内容复制到.git目录下
Git clone --template=<template-dir> <remote-repo>
【不同协议对git clone命令的影响】
ssh协议,git clone之前需要在server端配置ssh public key,配置一次即可
ssh://[user@]host.xz[:port]/path/to/repo.git/
git协议,不需要验证
git://host.xz[:port]/path/to/repo.git/
http协议,每次clone都需要输入user、ps
http[s]://host.xz[:port]/path/to/repo.git/
问题:如何remote repo的HEAD
1.3 git config
【Configuration level】
- Defualt local level, --local,local config存储在.git/config中
- Global level, --global,global config存储在用户home目录下的.gitconfig中,user级别的,~/.gitconfig
- Systme level,--system,machine级别的,存储在系统根目录的gitconfig中,linux在etc/gitconfig,windows,
C:\ProgramData\Git\config
读config
git config --global user.email
写config
git config --global user.email<value>
【别名alias】
就是用于简写高频词的长命令或复杂组合命令。
将commit简写为ci:git config --global alias.ci commit
将ci --amend简写为amend: git config --global alias.amend "ci --amend"
1.4 git alias
将已有命令简化:
$ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.ci commit $ git config --global alias.st status |
将组合命令简化
git config --global alias.unstage "reset HEAD --"
shiyshingss