This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
git [2018/06/29 13:17] jordan ↷ 页面vcs:git被移动至git |
git [2023/03/08 16:09] (current) xujianglong ↷ Page moved from 内部资料:git to git |
||
---|---|---|---|
Line 1: | Line 1: | ||
Git作为VCS(Version Control System)的一种,与另一个比较有名的svn的最大区别在于Git是分布式,svn是集中式。具体来说,Git不分服务器端和客户端,只有远程仓库和本地仓库,两者完全平等,因此,Git可以离线查看日志和提交代码。 | Git作为VCS(Version Control System)的一种,与另一个比较有名的svn的最大区别在于Git是分布式,svn是集中式。具体来说,Git不分服务器端和客户端,只有远程仓库和本地仓库,两者完全平等,因此,Git可以离线查看日志和提交代码。 | ||
- | # 新手入门 | + | ====== Git操作最佳实践 ====== |
+ | |||
+ | * 每次完成一个最细粒度的功能点或者每修复一个bug就提交一次代码 | ||
+ | * 代码提交的message最好写对应的任务编号加任务描述(如果有任务管理系统的话) | ||
+ | * 每天早上pull一次代码,每天晚上pull并push一次代码,其他在有需要的时候pull push代码 | ||
+ | * 未完待续.. | ||
+ | |||
+ | ====== | ||
很多时候并不需要每个人都创建仓库,只需要一个人创建既可。因此我们从git clone到git push到git pull的整个过程介绍Git入门。 | 很多时候并不需要每个人都创建仓库,只需要一个人创建既可。因此我们从git clone到git push到git pull的整个过程介绍Git入门。 | ||
- | ## 推荐教程 | + | ===== 推荐教程 |
- | * [Git教程|菜鸟教程](http:// | + | |
- | * [廖雪峰Git教程](https:// | + | * [[https:// |
- | * [Pro git](https:// | + | * [[https:// |
- | * [码云帮助文档](http:// | + | * [[http:// |
- | ## 常用操作 | + | ===== 常用操作 |
- | {{: | + | {{: |
- | * Clone远程仓库(repository):`git clone < | + | |
- | * 添加untracked file:`git add < | + | * 添加untracked file:''< |
- | * 提交tracked files:`git commit -m < | + | * 提交tracked files:''< |
- | * 推送到远程仓库:`git push` | + | * 推送到远程仓库:''< |
- | * 获取最新修改:`git pull` | + | * 获取最新修改:''< |
- | * 查看工作区状态:`git status` | + | * 查看工作区状态:''< |
- | * 查看日志:`git log` | + | * 查看日志:''< |
- | * 回收未提交代码:`git stash` | + | * 回收未提交代码:''< |
- | * 恢复未提交代码:`git stash pop` | + | * 恢复未提交代码:''< |
- | * 放弃所有未提交代码(不含新增文件):`git checkout -- .` | + | * 放弃所有未提交代码(不含新增文件):''< |
- | * 切换分支:`git checkout < | + | * 切换分支:''< |
- | * 退出git pull时跳转后的消息页面,直接输入`:q`然后敲击回车即可退出(vim编辑器) | + | * 退出git pull时跳转后的消息页面,直接输入''< |
- | ## git生成并添加ssh公钥方法 | + | ===== git生成并添加ssh公钥方法 |
- | *详见连接: http:// | + | *详见连接: http:< |
- | # Git flow | + | ===== Git打包不同分支的修改 ===== |
- | [Git flow创始人博客文章](http:// | + | < |
- | [Git flow快速入门Gitflow Workflow](https:// | + | - Git切换到需要打包的分支 |
+ | - 使用命令打包文件,''< | ||
- | [git flow的工作流程](https:// | + | ===== Git命令行如何记住密码 ===== |
- | ## Git flow 常见问题 | + | <code bash> |
+ | # 15分钟内不需要再次输入密码 | ||
+ | git config credential.helper cache | ||
+ | # 已经记住密码的情况下,想更改用户 | ||
+ | git config --unset-all credential.helper | ||
+ | git config --global --unset-all credential.helper | ||
+ | sudo git config --system --unset-all credential.helper | ||
- | ### 使用Git flow进行分支管理,是否需要执行git commit和git push等操作? | + | </ |
+ | |||
+ | ====== Git分支管理 ====== | ||
+ | |||
+ | ===== 为什么要使用Git分支管理 ===== | ||
+ | |||
+ | - 开发阶段,出现重大变化,老的版本不想丢掉,新的版本要开始做,因此需要分支管理 | ||
+ | - 已上线项目,加功能、改bug,如果动了正在运行的代码所在分支,导致不敢发布 | ||
+ | - 不同的目的需要不同的分支来管理,比如改bug要用改bug的分支,新功能要用新功能的分支 | ||
+ | |||
+ | ===== 为什么用Git Flow进行分支管理 ===== | ||
+ | |||
+ | - Git Flow自动化分支管理,基于哪个分支开新分支,如何合并分支,都有标准化流程 | ||
+ | - Git Flow得到了大多数工具的支持,例如命令行、Source Tree、IntelliJ Idea等 | ||
+ | - Git Flow是分支流程管理规范,也是工具,通过工具规范化便捷化分支管理 | ||
+ | |||
+ | ===== Git Flow基本教程 ===== | ||
+ | |||
+ | {{https:// | ||
+ | |||
+ | 使用举例: | ||
+ | |||
+ | - 开发新功能:git flow feature start membership,git flow feature finish membership | ||
+ | - 修复线上bug: | ||
+ | - 发布新版本: | ||
+ | |||
+ | ===== Git Flow详细教程 ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | |||
+ | ===== Git Flow 常见问题 ===== | ||
+ | |||
+ | ==== 使用Git flow进行分支管理,是否需要执行git commit和git push等操作? | ||
Git flow是分支管理规范与工具,因此对原本的代码提交、拉取等没有任何影响,只是简化了分支切换、合并和删除操作。 | Git flow是分支管理规范与工具,因此对原本的代码提交、拉取等没有任何影响,只是简化了分支切换、合并和删除操作。 | ||
- | ### 使用Git flow进行分支管理时,我怎么判断应该基于哪个分支创建新的分支? | + | ==== 使用Git flow进行分支管理时,我怎么判断应该基于哪个分支创建新的分支? |
+ | |||
+ | Git flow默认master和develop两个分支为基础分支,创建feature和release分支时基于develop,创建hotfix分支时基于master,与当前所在分支无关。详见[[https:// | ||
- | Git flow默认master和develop两个分支为基础分支,创建feature和release分支时基于develop,创建hotfix分支时基于master,与当前所在分支无关。详见[Git flow分支管理示意图](https:// |