Git 常用命令
Git结构
本地库 | git commit | 暂存区 | git add | 工作区
Git命令
本地初始化
$ git init
设置签名
以这组为例
用户名:xxx
邮箱:[email protected]
本地库有效
$ git config user.name xxx
$ git config user.email [email protected]
该内容保存在 ./.git/config 文件中
全局库有效
$ git config -global user.name xxx
$ git config -global user.email [email protected]
该内容保存在 ~/.gitconfig 文件中
主要操作
- 查看状态
$ git status
- 添加
$ git add [文件名]
- 提交
$ git commit -m "提交信息" [文件名]
- 历史记录
$ git reflog //本人常用
- 版本控制
$ git reset --hard [局部索引] //本人常用
- 删除文件找回
前提:文件提交到了本地库
$ git reset --hard [HEAD位置]
- 比较文件
工作区与暂存区文件比较
$ git diff [文件名]
工作区与本地库历史版本文件比较
$ git diff [本地库历史版本] [文件名]
分支操作
- 创建分支
$ git branch [分支名]
- 查看分支
$ git branch -v
- 切换分支
$ git checkout [分支名]
- 合并分支
$ git checkout [被合并分支名]
$ git merge [分支名]
提交到远程库
- 创建远程库别名
$ git remote add [别名] [远程库地址]
2.查看远程库名及地址
$ git remote -v
- 提交到github
- 没有设置远程库名的情况
$ git push [远程库地址] [分支名]
- 设置远程库名后的情况
$ git push [远程库别名] [分支名]
克隆到本地
$ git clone [远程库地址]
拉取到本地
pull = fetch(拉取) + merge(合并)
$ git pull [远程库地址] [远程分支名]
本文如有错误请诸君及时联系本人,我会尽快更正
QQ: 1334393949
邮箱: [email protected]