一.配置
git config user.name "lamplcc" //设置用户名
- 设置邮箱
git config user.email "lcc090202@sina.com" - 设置全局用户名
git config --global user.name "lamplcc" - 设置全局邮箱
git config --global user.email "lcc090202@sina.com" - 查看配置
git config --list
二.仓库
- 当前目录新建y一个代码库
git init - 检出仓库
git clone - 检出标签处的仓库
git clone --branch [tags标签] [git地址] - 查看远程仓库
git remote -v - 添加远程仓库
git remote add [name] [url] - 删除远程仓库
git remote rm [name] - 拉取远程仓库
git pull - 添加指定文件到暂存区
git add - 删除工作区和暂存区文件
git rm - 停止追踪指定文件,保留该文件在指定区
git rm --cached - 工作区和暂存区文件重命名
git mv - 提交暂存区到仓库
git commit -m 'message' - 提交时显示所有diff信息
git commit -v - 替换上一次提交
git commit --amend -m [message] - 推送到远程仓库
git push
三.信息查看与对比
- 查看提交日志
git log - 查看指定文件的提交日志
git log -p [file] - 以列表方式查看指定文件的提交历史
git blame [file] - 查看状态
git status - 查看变更的内容
git diff
四.查询详细指令
git --help
git help -a
git help -g
git help <command>
五.撤销
- 恢复暂存区的指定文件到工作区
git checkout [file] - 恢复某个 commit 的指定文件到工作区
git checkout [commit] [file] - 恢复上一个 commit 的所有文件到工作区
git checkout . - 重置暂存区的指定文件与上一次 commit 保持一致,工作区不变
git reset [file] - 重置暂存区与工作区,与上一次 commit 保持一致
git reset --hard - 重置当前分支的 HEAD 为指定 commit,同时重置暂存区和工作区,与指定 commit 一致
git reset --hard [commit] - 重置当前分支的指针为指定 commit,同时重置暂存区,工作区不变
git reset [commit] - 重置当前 HEAD 为指定 commit,但保持暂存区和工作区不变
git reset --keep [commit] - 撤销指定的提交
git revert [commit]
六.分支
- 查看本地分支
git branch - 查看远程分支
git branch -v - 创建分支
git branch [branch-name] - 切换分支
git checkout [branch-name] - 创建并切换分支
git checkout -b [branch-name] - 删除分支
git branch -d [branch-name] - 合并分支
git merge [branch-name]
七.标签
- 查看标签
git tag - 查看远程标签
git tag -r - 创建标签
git tag [tag-name] - 创建带注释的标签
git tag -a [tag-name] -m 'message' - 删除标签
git tag -d [tag-name]