一、开发时常用的指令
1. github配置 ssh key配置
cd ~/.ssh
查看是否有id_rsa、id_rsa.pub文件,如果没有需要手动生成。
ssh-keygen -t rsa -C "youremail@example.com"
一路回车.
登录github。打开setting->SSH keys,点击右上角 New SSH key,把生成好的公钥id_rsa.pub放进 key输入框中
2. git常用命令
git branch -a
//显示分支一览表,同时确认当前所在的分支git checkout -b aaa
//创建名为aaa的分支,并且切换到aaa分支 //创建名为aaa的分支git checkout aaa
// 切换到aaa分支git checkout -
//切换到上一分支
本地代码修改了,需要提交到另外一个未建新分支git checkout -b newBranch
// 直接在本地新建git push origin newBranch
// add&&commit后,直接推送该分支
同步远程分支列表(如:本地缺少分支,远程上有新分支添加’updateBranch’)git branch -a
// 查看本地和远程的分支git remote update origin --prune
// 更新本地分支列表。git checkout updateBranch
// 直接切换到该新分支updateBranch
不小心commit了一个不应该commit的修改,但是还没有push,想回滚那个commit.
命令:git log
// 查看提交日志 复制下commit_idgit reset --hard commit_id
// 回滚
查看更改的记录(后面可以加具体的文件名)git diff
合并本地 分支代码git merge test
// test为合并进来的分支
远程仓库查看git remote -v
添加远程仓库git remote add upstream https://github.com/xxxxx/kts-portal.git
重置远程仓库路径git remote set-url upstream https://github.com/xxxxxx/SpringBoot.git
更新远程分支列表git remote update origin --prune
git remote update origin -p
拉取远程某个分支git pull upstream dev
3. commit 提交类型规范
用于说明 commit 的类别,只允许使用下面7个标识。
feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试
chore:构建过程或辅助工具的变动
4. tag 使用
我们常常在代码封板时,使用git 创建一个tag ,这样一个不可修改的历史代码版本就像被我们封存起来一样,不论是运维发布拉取,或者以后的代码版本管理,都是十分方便的。
- 创建tag
git tag <name>
$ git tag v1.0 -m"备注" // 默认最近一次提交的commit $ git tag v1.0 <commitID> -m"备注" // 提交过的历史 打tag,找出对应的commit id
- 查看tag
git tag
- 提交
$ git push origin --tags
- tag覆盖
$ git tag -d V1.0 $ git push origin --tags
二、开发应用中出现的问题 解决
1、Failed to connect to github.com port 443:connection timed out
或 fatal: unable to access 'https://github.com/xxxx': gnutls_handshake() failed: The TLS connection was non-properly terminated
由于代理设置有错,为 http 错误配置了 https 的代理,导致出错。
设置如下:
git config --global http.proxy http://127.0.0.1:1080
git config --global http.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
还不行,有可能是dns解析出错,修改hosts文件。liunx所在路径:/etc/hosts
,windows所在路径:C:\Windows\System32\drivers\etc
192.30.255.112 github.com git
185.31.16.184 github.global.ssl.fastly.net