协同开发
1、引子:假如三个人共同开发同一份代码,每个人都各自安排了任务,当每个人都完成了一半的时候,提交不提交呢?
要提交,提交到dev吗,都上传了一半,这样回家拿出来的代码根本跑不起来。所以,
为每一个人创建一个分支,各自都在各自的分支上写代码,互不影响。
很短时间内大家暂时先合并一次,不然冲突太多了。但是这个分支不是dev,而是review分支,当老大看完没问题之后再合并到dev分支。
协同开发的两种方式:
方式一:创建项目合作者:
码云:
github:
方式二:创建组织,邀请成员
码云:
github:
创建完之后写代码
先创建了一个dev的分支 git branch dev git checkout dev git push origin dev 又创建了一个review的分支 git branch review gir checkout review git push origin review 创建自己的分支 git branch a git branch b git branch c git checkout c git pull origin review
假如现在有两个人在进行开发
A创建了个文件 git branch A git checkout A touch a.py git add . add commit -m 'inital' git push origin A ls vim a.py #写了一些内容 git add . add commit -m 'a功能开发完毕' git push origin A #现在两人都写完了,开始合并和review进行合并了 git checkout review git pull origin review #远程的review拉下来 #合并发到review git merge A ls git status git push origin review #再次写的时候 git pull origin review B创建了个文件 git branch B git checkout B touch b.py ls git add . add commit -m 'b功能开发完毕' git push origin B ls vim c.py #写了一些内容 git add . add commit -m 'c开发完毕' git push origin B #现在两人都写完了,开始合并和review进行合并了 git checkout review #git pull origin review #如果先没有,把远程的review拉下来 #合并发到review git merge B ls git status git push origin review #这时候的review是最新的,那么A先提交了,完了B还得拉先来再合并一次 老大看了review分支,如果OK,可以放到dev分支进行测试,如果测试没有问题了 才放到master分支。 master分支:线上的版本,永远保证线上的版本,无论是回滚到哪都是能用的
GIT忽略文件
当你提交代码的时候不要把所有的代码都提交,尤其是你自己的隐藏文件,还有pycharm自动生成的隐藏文件,
两个方式:
手动修改:在你add的时候不要把它添加进去就行了
创建.gitignore文件
码云:
github:
修改 :需要改一下配置文件
.gitignore vim . gitignore /idea touch a.log touch b.log 不要所有.log文件了,在编辑的时候写上*.log
一些规则
以斜杠“/”开头表示目录; 以星号“*”通配多个字符; 以问号“?”通配单个字符 以方括号“[]”包含单个字符的匹配列表; 以叹号“!”表示不忽略(跟踪)匹配到的文件或目录;
样板:
# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log .static_storage/ .media/ local_settings.py # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # pyenv .python-version # celery beat schedule file celerybeat-schedule # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/
GIT版本Tag
git tag -a V0.1 -m 'version0.1' 本地创建Tag git show v0.1 查看 git tags -n 查看本地Tag git tag -l 'v1.*' 查看本地Tag,模糊匹配 git tag -d v0.1 删除Tag git push origin :refs/tags/v0.2 更新远程tag git checkout v0.1 切换tag git fetch origin tag V1.2 git push origin 0.1 git pull origin 0.1 git clone -b v0.1 #操作示例 XXX MINGW64 ~/PycharmProjects/study (dev) $ git tag -a V0.1 -m 'version0.1' XXX MINGW64 ~/PycharmProjects/study (dev) $ git show v0.1 tag V0.1 Tagger: XXX <XXX@qq.com> Date: Sun Jul 1 00:13:25 2018 +0800 version0.1 commit cc915e200275d56f8630a35043e5c973c9521233 (HEAD -> dev, tag: V0.1) Merge: fb39758 8a7f6ea Author: XXX <XXX@qq.com> Date: Sat Jun 30 13:45:28 2018 +0800 merge 3.py:Merge branch 'dev' of https://gitee.com/XXX/study1 into dev XXX MINGW64 ~/PycharmProjects/study (dev) $ git tag -n V0.1 version0.1 XXX MINGW64 ~/PycharmProjects/study (dev) $ git tag -l 'V*' V0.1 $ git checkout V0.1 Note: checking out 'V0.1'. XXX MINGW64 ~/PycharmProjects/study ((V0.1)) $ git push origin V0.1 Counting objects: 5, done. Delta compression using up to 8 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 620 bytes | 620.00 KiB/s, done. Total 5 (delta 2), reused 0 (delta 0) remote: Powered by Gitee.com To https://gitee.com/XXX/study1.git * [new tag] V0.1 -> V0.1 XXX MINGW64 ~/PycharmProjects/study ((V0.1)) $ git pull origin V0.1 From https://gitee.com/XXX/study1 * tag V0.1 -> FETCH_HEAD Already up to date.
查看tag: