1.本地操作
1.1 git init
1.2 设置签名
1.2.1 项目(仓库)级别仅在当前本地库有效
git config user.name tom #设置用户名tom
git config user.email liu@qq.com #设置用户邮箱
1.2.2 系统用户级别仅在当前登录的操作系统用户有效
git config --global user.name tom
git config --global user.email liu@qq.com
cat .git/config 或 cat .gitconfig 查看
1.3 git status #查看工作区、暂存区状态
1.4 添加
git add fileName #指定文件
git add . #所有
说明:将工作区的文件添加到暂存区
git rm --cached .babelrc 撤回 .babelrc文件
1.5 git commit -m 'commit message' fileName 提交
1.6 历史纪录
git log #(HEAD -> master) 指针
git reflog #常用
git log --greph #图形显示,更直观
git log --pretty=oneline #漂亮一行显示
git log --oneline #简洁显示
说明:HEAD@{移动到当前版本需要多少步}
1.7 后退
git reset --hard a6ace91
git reset --hard HEAD^^ #几个 ^ 表示后退几步
git reset --hard HEAD~3 #只能后退
1.8 删除文件找回
1.8.1 文件状态在本地库
git reset --hard 指针位置(指针指向历史记录)
1.8.2 文件状态在暂存区
git reset --hard 指针位置(指针位置使用head)
1.9 分支
git branch 分支名 #创建
git branch -v #查看
git checkout 分支名 #切换
git branch -d 分支名 #删除
1.9.1 合并分支
先切换到被合并的分支上(主分支),
git merge xxx
2. Git 结合Github
2.1创建远程库地址别名
git remote add origin <u>https://xx</u> origin为别名
git remote -v #查看远程地址别名
2.2 将文件推送到仓库
git push 别名 分支名
git push -u 别名 分支名 #-u指定默认主机
Git push -u origin master
2.3 克隆
完整的把远程库克隆到本地 克隆下来后不要在主分支里面做开发 clone进行一次,从无到有的过程,更新用pull,不用初始化
git clone 远程地址
本地存在clone下来的文件 就用pull更新 git pull 别名 分支名
2.4跨团队协作
先在别人的github中点fork,本地修改再推送仓库,点击pullrequset,new pull request,create pullrequest
邀请成员:Settings --> Collaborators -->填写用户名 -->打开链接接受邀请
2.5 SSH 免密登录
· 输入:ssh-keygen -t rsa -C GitHub邮箱地址
· 进入.ssh目录(cd .ssh/),复制id_rsa.pub文件内容(cat id_rsa.pub)
· 登录GitHub。Settings --> SSH and GPG keys --> New SSH Key
· 回到git通过ssh地址创建。git remote add 别名 SSH地址
2.6 tag
git tag -a v1.0 -m '版本介绍' #创建本地tag信息
git tag -d v1.0 #删除tag
git push origin --tags #将本地tag信息推送到远程库
git pull origin --tags #拉取到本地
git checkout v.10 #切换tag
git clone -b v0.1 地址 #指定tag下载代码