caitiao的博客

就现在,Just do it

0%

常用Git命令

提交文件到索引中 git add

1
2
3
4
git add -A #将所有新增、修改、删除的文件提交到索引中
git add -u #将所有修改、删除的文件提交到索引中
git add . #将所有新增、修改、删除的文件提交到索引中
git add --ignore-removal . #将所有新增、修改的文件提交到索引中

查看文件每行的最后提交人和时间 git blame

1
2
3
git blame <file> #查看文件每行的最后提交人和时间
git blame <file> -L :<funcname> #查看文件某个方法的最后提交人和时间
git blame <file> -L <start>,<end> #查看文件行数范围内的最后提交人和时间

查看所有分支,并显示版本信息

1
git branch -v

在本地创建远程分支

1
git checkout -b <local-branch-name> origin/<remote-branch-name>

clone项目

1
2
git clone <giturl>
git clone http://<username>:<password>@<giturl> #带用户名密码

git配置 git config

1
2
3
4
5
git config --global credential.helper cache #全局模式缓存凭证 15 分钟
git config --global credential.helper store #全局模式储存仓库凭证
git config --global user.email "youremail@gmail.com" #全局配置 git 邮箱
git config --global user.name "your name" #全局配置 git 用户名
git config credential.helper store #储存当前仓库凭证

把远程分支拉到本地 git fetch

1
git fetch origin <branch_name>

初始化当前目录为仓库 git init

1
2
git init
git init <repo_name> #创建 仓库

git log

1
git log --stat --author=<pattern> --after=<date> --before=<date> #查看某人一段时间的提交记录,并显示详情

撤销所有合并操作

1
git merge --abort

拉取远程分支到本地

1
git pull origin <branch-name>