AKSTIANYE

Mar 23, 2018

git 入门

初始化参数

1
2
git config --global user.name "你的名字"
git config --global user.email "你的邮箱地址"

保存账号密码

  • 记住密码(默认15分钟)
1
git config --global credential.helper cache
  • 自己设置时间(单位,秒)
1
git config credential.helper 'cache --timeout=3600'
  • 长期保存
1
git config --global credential.helper store

常用命令

  • 克隆项目
1
2
3
4
// 克隆master分支
git clone <版本库的网址>
// 指定克隆的分支名
git clone -b <分支名> <版本库的网址>
  • 查看状态
1
2
3
4
// 查看当前状态
git status
// 查看本地仓库的提交历史
git log
  • 提交代码
1
2
3
4
5
6
// 添加文件包版本控制
git add <文件>
// 提交到本地仓库
git commit -m '提交说明'
// 提交代码到远程仓库
git push origin <分支名>
  • 更新代码
1
git pull origin <分支名>

一次简单的流程

先将代码clone到本地

1
git clone <项目地址>

添加一个新文件,并将新文件添加到版本控制

1
git add init.txt

提交到本地仓库

1
git commit -m '添加了一个新文件' 

将文件init.txt修改一点内容,再次提交

1
2
git add init.txt
git commit -m '修改了一点内容'

将文件提交到远程仓库

1
git push origin <分支,默认master>
OLDER > < NEWER