一、下载并安装git
二、开始操作
- 右键然后点击git bash进入命令框
- 命令是仿照linux,可以使用ls,pwd,cd
- 创建一个文件夹,在此路径下git init,创建了一个仓库,会有一个.git文件
- 三、配置仓库
- git config --global user.name “用户名字”
- git config --global user.email “邮件地址”
四、基本操作
1. 添加提交内容
- git add sunck.txt
- git commit -m “第一次添加”
git add .
git commit . -m “全部提交”
2. 查看状态
- git status
//告诉你哪个文件被改变了 - git diff
//查看修改的内容 - git log
//查看日志
$ git log
commit f08b4228397124c50d65583567e5c217801d9fe4 (HEAD -> master)
Author: liangxinxin5102 <1974733812@qq.com>
Date: Sun Dec 29 01:04:33 2019 +0800
一次添添加
会显示提交的编号,分支,用户,时间,注释
$ git log --pretty=oneline
f08b4228397124c50d65583567e5c217801d9fe4 (HEAD -> master) 一次添添加
3. 回归版本
- git reset --hard HEAD^ 回到上一版本
- git reset --hard HEAD^^ 回到上上一版本
- git reset --hard HEAD~100 回到上100版本
- git reset --hard HEAD 具体版本号
- git refog 记录每一次提交的命令
4. 工作区与缓存区
- checkout --filename //让文件回到add或者commit状态
5. 连接GitHub服务器–密钥与公钥
- ssh-keygen -t rsa -C “1974733812@qq.com”
- ssh -T git@github.com #测试是否连接成功
注意记录位置,要将公钥复制粘贴到github账号的设置里
6. 创建远程仓库
- 关联远程仓库 git remote add origin https://github.com/liangxinxin5102/git_test1.git
- 删除关联 git remote rm origin
7. 远程仓库的推送与拉取
(先要拉取,才能推送 git pull origin master --allow-unrelated-histories)
- 推送 git push origin master
- 拉取 git pull origin master
正常情况下我们没有本地库,开发一般是现有远程库再克隆本地库,这样远程就不会和本地冲突了
- 克隆 git clone https://github.com/liangxinxin5102/git_test1.git
8. 不提交指定文件
- 创建文件 touch .gitignore
- 在 .gitignore文件中填写不提交的文件名,此目录下的文件不会被提交, .gitignore文件会提交上去
五、分支
- 创建分支 git branch 分支名
- 切换分支 git checkout 分支名
- 创建与切换同时进行 git checkout -b 分支名