Git仓库创建及其工作流
$ git config --global user.name "名字" 配置用户名
$ git config --global user.email "邮箱" 配置邮箱
$ git config --list 查看配置
$ pwd 查看当前目录位置
$ ll 查看目录下文件信息
$ ls 查看目录有什么文件
$ ls -a 查看隐藏文件
$ mkdir demo 创建文件夹demo
$ git init 初始化版本库
$ echo "git repo2" >> test.txt 添加内容到文本
$ cat test.txt 查看文件内容
$ git add test.txt 添加文件到暂存区
$ git commit -m "repo2 first commit" (提交 "repo2 first commit" :描述信息)添加文件到版本库
$ git status 查看仓库状态
$ git reset HEAD bash_demo.txt 通过仓库HEAD把暂存区的修改回退到修改之前(工作区文件不会改变)
$ git checkout -- bash_demo.txt 将工作区(本地)改变(弄干净)
$ git log 查看日志
$ git reset --hard 2be6717eb22779165e539fe6015a92f40300a6ad 回滚到某一次提交(commit号) --hard 最终仓库和暂存区的文件回滚到某一次提交
$ git rm bash_demo.txt 本地(工作区清空,删除文件) 但是暂存区和仓库还没清空
$ git commit -m "delete bash demo" 清理暂存区和仓库
远程仓库
$ git pull origin master 拉取代码到本地
$ echo "# 随意文字内容" >> README.md
$ ssh-keygen -t rsa -C "email@..." github上注册的邮箱
id_rsa.pub 公钥
将公钥拷贝到github上
$ ssh -T git@github.com
$ git init 初始化git仓库
$ git add README.md 添加到暂存区
$ git commit -m "first commit"
$ git remote add origin git@github.com:github上用户的名字/仓库名.git 本地仓库和远程仓库关联
$ git push -u origin master
在演示一遍
$ vim README.md
$ git add README.md
$ git commit -m "second commit"
$ git push
克隆仓库
$ git clone git@github.com:github上用户的名字/仓库名.git
$ echo "clone demo" >> clone.txt
$ cat clone.txt
$ git status
$ git add clone.txt
$ git status
$ git commit -m "first clone commit"
$ git push
标签管理
$ git tag 查看所有标签
$ git tag name 创建标签
$ git tag -a name -m "comment" 指定提交信息
$ git tag -d name 删除标签
$ git push origin name 标签发布
$ echo “new code” >> test
$ git status
$ git add test
$ git commit -m "new code commit"
$ git status
$ git push
$ git tag
$ git tag v1.0.1
$ git tag
$ git push origin v1.0.1
$ git tag -d v1.0.1
分支管理
$ git init
$ git status
$ echo "first branch demo" >> branch.txt
$ git status
$ git add branch.txt
$ git commit -m "first branch commit"
$ git status
$ git branch feature_x 创建feature_x分支
$ git branch 查看分支
$ git checkout feature_x 切换分支
$ git branch 这时*号在feature_x分支上
$ git echo "new feature added" >> branch.txt
$ git add branch.txt
$ git commit -m "new feature add"
$ git status
首先切换到master分支,才能进行merge
$ git checkout master
$ git merge feature_x
$ cat branch.txt
分支不用了,删除操作
$ git branch -d feature_x
$ git branch