07-31-19 - 代码操作`GitLab`操作流程记

07-31-19 - 代码操作GitLab操作流程记

主线流程

git checkout 3.5-bugfix——拉取最新代码git pull——创建、切换到自己任务分支git checkout -b T000001——存到暂存区git stash——切换到提交分支,拉取最新代码——切回任务分支git checkout ——将提交分子最新代分支并到当前任务分支git merge 3.5-bugfix——取出暂存代码git stash pop检查错误——推送git push origin

详细流程

写代码之前,一定要先pull拉取最新代码

MINGW64 ~/Projects/odoo/kthrp (develop)$ git pull

然后切换到需要操作的任务分支(比如3.6-fixbug

MINGW64 ~/Projects/odoo/kthrp (develop)$ git checkout 3.6-bugfixM       kthrp_base/views/kthrp_calendar_view.xmlM       kthrp_stock/__init__.pyBranch 3.6-bugfix set up to track remote branch 3.6-bugfix from origin.Switched to a new branch ‘3.6-bugfix‘

再pull一下代码

MINGW64 ~/Projects/odoo/kthrp (3.5-bugfix)$ git pullremote: Counting objects: 12, done.remote: Compressing objects: 100% (12/12), done.remote: Total 12 (delta 2), reused 0 (delta 0)Unpacking objects: 100% (12/12), done.From http://61.183.163.210:81/kthrp/kthrp   7ab182a..9ca22ac  3.6-bugfix -> origin/3.6-bugfix   91742d9..96576ed  develop    -> origin/developAlready up-to-date.

然后创建自己的分支进行代码操作(分支名T000001

$ git checkout -b T000001Switched to a new branch ‘T000001‘

查看代码修改的状态

MINGW64 ~/Projects/odoo/kthrp (T000001)$ git statusOn branch T000001Changes not staged for commit:  (use "git add <file>..." to update what will be committed)  (use "git checkout -- <file>..." to discard changes in working directory)?        modified:   kthrp_account/models/account_account.py?Untracked files:  (use "git add <file>..." to include in what will be committed)?        todo_app/        todo_calendar/        todo_kanban/        todo_report/        todo_ui/        todo_user/        todo_wizard/?no changes added to commit (use "git add" and/or "git commit -a")

查看具体的哪些代码被修改了

MINGW64 ~/Projects/odoo/kthrp (T000001)$ git diffdiff --git a/kthrp_account/models/account_account.py b/kthrp_account/models/account_account.pyindex 348afda..298d926 100644--- a/kthrp_account/models/account_account.py+++ b/kthrp_account/models/account_account.py@@ -15,6 +15,10 @@ class KthrpAccountAuxiliaryType(models.Model):     _name = "kthrp.account.auxiliary.type"     _description = "Kthrp Account Auxiliary Type"?++++     name = fields.Char(‘Type‘,required=True,translate=True)     code = fields.Char(‘Type Code‘,required=True)?

代码操作完毕以后,将代码放置暂存区

MINGW64 ~/Projects/odoo/kthrp (T000001)$ git stashSaved working directory and index state WIP on T000001: 634c424 Merge branch ‘T5986‘ into ‘3.5-bugfix‘HEAD is now at 634c424 Merge branch ‘T5986‘ into ‘3.5-bugfix‘

回到任务分支

MINGW64 ~/Projects/odoo/kthrp (T000001)$ git checkout 3.5-bugfixSwitched to branch ‘3.5-bugfix‘Your branch is up-to-date with ‘origin/3.5-bugfix‘.

git pull拉取最新代码

再回到自己的分支git checkout T000001

合并代码

MINGW64 ~/Projects/odoo/kthrp (T000001)$ git merge 3.5-bugfixAlready up-to-date.

取出暂存区的代码

MINGW64 ~/Projects/odoo/kthrp (T000001)$ git stash popOn branch T000001Changes not staged for commit:  (use "git add <file>..." to update what will be committed)  (use "git checkout -- <file>..." to discard changes in working directory)?        modified:   kthrp_account/models/account_account.py?Untracked files:  (use "git add <file>..." to include in what will be committed)?        todo_app/        todo_calendar/        todo_kanban/        todo_report/        todo_ui/        todo_user/        todo_wizard/?no changes added to commit (use "git add" and/or "git commit -a")Dropped refs/{0} (2e5565e706d17151b0af49d1e71500d812e7af3b)

再提交add,commit

push origin接自己的分支号 推送代码

在GitLab上完成提交后,到docker中pull,再重启服务

服务器内网$ ssh

外网 MINGW64 ~/Projects/odoo/kthrp (3.5-bugfix) $ ssh -p 115

最新的develop是12分支,集测对应的是15,现在3.6代发布版本都是15

docker重启

当代码提交完成,再GitLab上获得肯定以后,登陆docker

ssh

然后输入自己的GitLab的账号和密码,然后拉取代码git pull

在确认可以重启以后,输入命令

docker-compose restart 对应的模块(例如kthrp)

操作就完成了

MINGW64 ~/project/odoo/kthrp (develop)$ ssh The authenticity of host ‘192.168.1.12 (192.168.1.12)‘ can‘t be established.ECDSA key fingerprint is SHA256:kvHOdtxtddI+92HWo1VvxP9SS6JtG7ZNOSeLQ/s5b5c.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added ‘192.168.1.12‘ (ECDSA) to the list of known hosts.‘s password:Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-139-generic x86_64)? * Documentation:  https://help.ubuntu.com/?172 packages can be updated.0 updates are security updates.??Last login: Mon Aug  5 17:29:28 2019 from 192.168.1.1warning: unable to access ‘/home/kthrp/.config/git/attributes‘: Permission deniedwarning: unable to access ‘/home/kthrp/.config/git/ignore‘: Permission deniedOn branch developYour branch is up-to-date with ‘origin/develop‘.nothing to commit, working directory clean:/u01/kthrp/code/kthrp$ git pullUsername for ‘http://192.168.1.9‘: wangjianhangPassword for ‘http://‘:remote: Counting objects: 2, done.remote: Compressing objects: 100% (2/2), done.remote: Total 2 (delta 0), reused 0 (delta 0)Unpacking objects: 100% (2/2), done.From http://192.168.1.9/kthrp/kthrp   c9e0e88..d33485d  develop    -> origin/developUpdating c9e0e88..d33485dwarning: unable to access ‘/home/kthrp/.config/git/ignore‘: Permission deniedwarning: unable to access ‘/home/kthrp/.config/git/attributes‘: Permission deniedFast-forwardwarning: unable to access ‘/home/kthrp/.config/git/attributes‘: Permission denied kthrp_hr/models/employee.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-):/u01/kthrp/code/kthrp$ docker-compose restart kthrpRestarting kthrp_kthrp_1 ... done:/u01/kthrp/code/kthrp$ exitlogoutConnection to 192.168.1.12 closed.?

如果操作涉及到数据库的改变,则需要升级相应模块,升级数据库。

15的环境,要在http://61.183.163.210:85/web/database/selector的SIT里面升级,12再:83里面升级

其他情况

1. 已经push了,但是还需要修改

git log

找到你commit的位置,找到相应位置下方的任务号

git reset --soft 任务号

就可以回退push操作,到add后,待commit阶段

这时候使用命令

git status

可以看到你已经add的文件,如果需要再修改add之外的文件,直接更改代码,再add,commit,push就行,但是如果你需要更改已经add了的内容的话,使用命令:(撤销add操作)

git reset HEAD 对应的文件名

这时候已经add的绿色的文件就会变成红色(待add阶段),你就可以修改内容了。

最后add,commit,push的时候会提示版本冲突,需要在push的命令后面添加-f(覆盖之前的提交请求)

git push origin 任务分支 -f

2. 拉取最新得主线分支

git fetch