1.前言
引用一篇非常全而且非常详细的git和GitHub教程
git-GitHub
出自 AWeiLoveAndroid的博客
2.一些细节补充
git config --global user.email "67678@163.com"
git config --global user.name "hellogit"
git config --global user.password "m"
//如果忘记 或者别人的电脑 可以替换 账号
git config --global --replace-all user.email “输入你的邮箱”
git config --global --replace-all user.name “输入你的用户名”
// 替换的第二种方式
// 会直接覆盖掉 原来的
git config --global user.email "邮箱"
- 图形化工具界面GitHub Desktop不错 windows和mac都有
2.提交的一般步骤
git clone 地址 (先切换到目录)
git fetch origin release……: release......(release直接打个re再按tab建就可以补全)
git checkout release....(release直接打个re再按tab建就可以补全)
拉取
git pull 先拉取最新的到本地 避免直接提交造成冲突
git pull <远程主机名> <远程分支名>:<本地分支名>
git pull origin
git pull origin master:brantest
提交
git add . 回车(表示添加到本地库 . 表示提交所有更改的内容)
git status 回车 (查看状态)
git commit -m " 信息" 回车(提交更新信息)
git push origin 分支名字 回车(推送到远程库的main分支)
git log 查看git日志 :提交信息等
配置
查询所有配置文件内容
git config --global --list
查询某个指定内容,例如 查询用户名
git config --global user.name
3.分支常用指令
常用
git branch 查看本地分支
git branch -r 查看远程分支
git branch [name] 创建本地分支,但是创建成功后并不会自动切换为当前分支
git checkout [name] 切换分支
//二合一 创建并立即切换到新分支
git checkout -b [name]
合并分支
git merge [name] 将名称为[name]的分支与当前分支合并
git push origin [name] 创建远程分支
回退到指定的历史版本id
git reset --hard 139dcfaa558e3276bafsfag5cbbb9c00bbdca96
4.tag操作相关
tag 一般都是上线的时候打,保留最近几次的tag不删除,以备恢复
git tag [name] 创建版本
git tag -d [name] 删除版本
git tag -r 查看远程版本
git push origin [name] 创建远程版本
git pull origin --tags 合并远程仓库的tag到本地
git push origin --tags 上传本地tag到远程仓库
5.远程仓库相关命令
git remote -v 查看远程仓库
git remote add [name][url] 添加远程仓库
git remotre rm [name] 删除远程仓库
git pull [remoteName][localBranchName] 拉取远程仓库
6.gitignore文件
告诉Git哪些文件不需要添加到版本管理中
语法表示注释
build/ 文件夹里所有文件一起被忽略 不提交
! 不忽略的文件
!dist/
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS or Editor folders
.DS_Store
._*
.cache
.project
.settings
.tmproj
*.esproj
*.sublime-project
*.sublime-workspace
nbproject
thumbs.db
*.iml
# Folders to ignore
.hg
.svn
.CVS
.idea
node_modules/
jscoverage_lib/
bower_components/
dist/
7. 文件 .gitignore 创建
查看隐藏文件windows
1.png
mac查兰隐藏文件更加编辑
Command + Shift + .
创建
git bash 进入到项目根目录
就是确保与.git在同一个目录就行
执行
touch .gitignore
2.png
8.遇到的问题及解决方案
问题 报错
error.png
原因及解决
一般是这是因为服务器的SSL证书没有经过第三方机构的签署
复制到终端执行 就哦了
其实这里遇到的问题可能比较多,遇到问题不要怕,百度一下你就知道
git config --global http.sslVerify "false"
- 保存账号密码
push的时候 需要每次都输入账号密码 ,很麻烦
可以再一次push成功操作后执行
git config --global credential.helper store
本机会创建文件记录账号密码 下次就不用在输入账号密码了