参考资料

Git教程
git - 简明指南

个人项目的版本控制流

  1. 下载安装git,进行user.name和user.email的配置
1
2
git config --global user.name "Your Name"
git config --global user.email "planckgh@gmail.com"
  1. 完成ssh密钥配置
1
ssh-keygen -t rsa -C "planckgh@gmail.com"
  1. 在本地工作目录新建git版本管理库
1
git init
  1. 新建工作文件(test.c)
1
vim test.c
  1. 添加改动文件至暂存区
1
2
3
4
# 单个文件
git add test.c
# 所有文件
git add .
  1. 完成阶段性工作后,提交至HEAD
1
2
3
4
5
6
# 无改动提交
git commit --allow-empty -m "text"
# 改动提示不长
git commit -m "text"
# 改动提示较长
git commit

  1. 创建分支&跳转分支
1
2
3
4
5
6
# 创建分支
git checkout -b pa2
# 跳转分支
git checkout master
# 合并分支(将pa2合并到当前分支master)
git merge pa2
  1. 查看版本提交记录
1
git log
  1. 回溯版本
1
git reset --hard 版本号
  1. 查看回溯历史
1
git reflog
  1. 推送至远程仓库
    1. 在github上创建新仓库,获取仓库链接
    2. 将本地仓库与远程仓库进行关联
    1
    git remote add origin https://github.com/planckzgh/ROIC.git
    1. 将本地仓库推送至远程仓库
    1
    git push (-u) origin master
    1. 修改本地仓库关联链接
    1
    git remote set-url origin https://github.com/planckzgh/ROIC.git