git

1
一个开源的分布式版本控制系统。

配置

git提供了一个git config工具,专门用来配置货读取相应的工作环境变量。

/etc/gitconfig:系统配置,使用 –system参数

~/.gitconfig:用户配置,使用 –global参数

用户和电子邮件

1
2
git config --global user.name "your name"
git config --global user.email "your email"

文本编辑器

1
git config --global core.editor "editor name"

查看信息

1
2
3
git config --list # 查看所有环境变量
git config <config name> # 查看制定的配置
git log # 查看提交历史信息

创建仓库

1
2
git init # 使用当前目录作为git仓库
git init <dir> # 指定目录作为git仓库

提交

1
2
3
git add <file> # 添加文件到缓存区 可使用正则表达式
git commit -m 'init project version' # 将缓存区文件提交到仓库
git status -s # 查看项目当前的状态

拷贝

1
git clone <repo> <directory> # 克隆到制定目录,repo:git仓库,directory:本地目录

取消

1
git reset HEAD <file name> # 将文件移出缓存区

删除

1
2
3
git rm <file> # 从git中删除文件
git rm -f <file> # 强制删除
git rm --cached <file> # 从跟踪清单中删除

移动

1
git mv <file> <dir> # 移动文件 可以重命名

分支

1
2
3
4
5
git branch # 查看分支
git branch <branch name> # 创建分支
git checkout <branch name> # 切换分支
git merge <branch name> # 合并分支
git branch -d <branch> # 删除分支

标签

1
2
git tag -a "tag name" # 创建一个带注解的标签
git tag # 查看所有标签

远程仓库

1
2
3
4
5
git remote add [short name][url] # 添加到远程仓库
git remote # 查看当前的远程仓库
git fetch # 提取远程仓库
git push [store] [branch] # 将分支推送到远程仓库
git remote rm [store] # 删除远程仓库

生产ssh-key

1
2
ssh-keygen -t rsa -C "your email" # 生成ssh-key
ssh -T git@github.com # 验证是否成功建立连接

搭建git服务器

安装git

1
2
groupadd git # 创建 git用户组
useradd git -g git # 创建用户

创建证书登录

1
2
mkdir .ssh
touch .ssh/authorized_keys

初始化git仓库

1
git init  --bare [store]

克隆仓库

1
git clone git@localhost:/仓库地址