工作中常用命令(git和k8s)

GIT

在本地分支.上开发

  1. 创建本地分支
  2. 现切换到master
git checkout master
git pull
  1. 建议使用单独的本地分支进行开发,可以用一下命令从当前分支创建一个本地分支。
git checkout -b <branch_name>
  1. 如果最终这个分支上的代码提交到远程分支上,为了防止分支名称冲突,建议使用自己的ldap作为前缀,比如pc- add- some-codes
  2. 提交本地修改
  3. Git 每次提交前需要把准备提交的文件添加到索引(Index)里面,可以使用git add 添加索引。
#添加所有修改过的文件和所有新文件
git add .
  1. 提交前可以使用git status 看当前工作目录的状态,也可以使用git diff查看具体修改内容,确认无误之后用一下命令提交。
git commit -m' commit msg '
  1. 代码格式检查
/Users/huangjialin/ .yc-scr ipts/ gi t-hooks/.. /git-fix. sh
  1. 查看本地分支
git branch

向GitLab提交代码

  1. git push 可以将本地分支到GitLab。 建议远程分支和本地分支使用同样的名字,如果远程分支不存在,GitLab会自动创建。
git push origin HEAD: <remote_ branch_ name>

#例如
#git@gi tlab. yaochn. com: infra/mixer.git
git push origin HEAD: infra/mixer.git

~/ business-directory jialin-alter-RoleType-code > git push origin HEAD:jialin-alter-RoleType-code
  1. 注意,不要使用git commit --amend或者git rebase 修改已经推送到远程的提交或者分支,否则会导致后续的推送失败。
  2. 可以设置git默认将本地分支推送到远程同名分支,这样在每次推送时省略refspec参数。
git config --global push.default current

分支获取最新代码

git fetch

git merge origin/master

git push origin HEAD: huangjialin-alter-some-codes

强制拉取并覆盖本地代码

git fetch --all

git reset --hard origin/ master

git pull

git pull 和 git fetch的区别?

https://www.zhihu.com/question/38305012

在这里插入图片描述

master获取最新代码

git checkout
master git pull

冲突解决

  1. 如果在运行git merge 时提示有冲突,那么就需要手动编辑有冲突的
  2. 文件。VSCode, IntelliJ都可以辅助解决合并冲突。冲突文件手工合并后, 需要用git add 标记冲突已解决,然后用以下命令继续完成合并。
git merge --continue

有时testing项目会拒绝commit,如果确定自己的代码格式没有问题,则可以选择使用以下命令进行强制提交

git commit -m "提交信息" -n

本地分⽀push到远程master时可能会出现落后远程分⽀拒绝push的提⽰,则可以尝试以下命令进⾏ 强制提交

git push origin HEAD:<remote_branch_name> -f

远程代码合并操作汇总

~/business-directory jialin-check-function > git checkout master 

... 

~/business-directory master > git pull 

... 

~/business-directory master > git checkout jialin-check-function 

.... 

~/business-directory jialin-check-function > git merge origin/master 

... 

~/business-directory jialin-check-function > git status 
4s py infra_test:infra_test 3.8.7 16:43:04 
位于分⽀ jialin-check-function 
⽆⽂件要提交,⼲净的⼯作区 

~/business-directory jialin-check-function > git merge origin/master 
py infra_test:infra_test 3.8.7 16:43:10 
已经是最新的。

进⾏以上操作即可完成本地分⽀与远程分⽀的合并

git 回退到某个commit

git log -3						#查看最新提交的三个版本号
git reset --hard HEAD^			#回退到上个版本
git reset --hard HEAD~3			#回退到前3次提交之前,以此类推,回退到n次提交之前
git reset --hard commit_id		#退到/进到指定commi t的sha码

强制清空本地commit

git stash git 
stash clear

选择stash

第⼀次stash:

> git stash

查询stash 列表:

> git stash list 
> stash@{0}: WIP on fixResponseType: 8ba2b28 add and change some logic 12

第⼆次stash:

> git stash

查询stash 列表:

> git stash list 
stash@{0}: WIP on emcache: c13f985 Merge pull request #12 from username/fixRespo nseType 
stash@{1}: WIP on fixResponseType: 8ba2b28 add and change some logic

可以看到 stash@{0} 是最新的缓存,stash@{1} 是第⼀次的stash,所以选择指定的缓存恢复的操作如 下:

> git stash pop stash@{1}

这个是恢复第⼀次的缓存

测试文件更新

在对应的api修改之后,如果进行测试需要更新其相应的测试文件
即在对应的分支下执行

pip install -U -r requirements.txt
~/testing jialin-refactor-roleCode +3 > pip install -U -r requirements. txt

K8S

重启k8s

  1. 销毁本地部署
kubecfg delete local/deployment.jsonnet
  1. 查看所有都pods被关闭
 kubectl get pods
  1. 重新部署
cd deployment
kubecfg update local/deployment.jsonnet
  1. 检查所有pods均被启动
kubectl get pods
  1. 开启nginx
kubectl port- forward service/nginx 9443: 443
kubectl port- forward service/nginx 8443: 443
kubectl port- forward service/nginx 8080: 80

开启成功后可访问
https://local.develop.yaochn.com:8443/ https://local.develop.yaochn.com:9443/
此⽅法会清空本地数据库

查看log⽇志

kubectl logs service/ auth-hub			#查看对应项目的的log
kubectl describe pod notificati on-77464c574-49bc7			#查看具体pod描述

异常监控

jenkins.yaochn.com 
https://jenkins.yaochn.com/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值