Git在idea上的简单实用
2017-04-17 本文已影响190人
皮卡亿千万
首先你需要对git有一定了解,可以看一下以下文章
git-简易指南
首先在gitlab上面创建一个新的项目,会有以下提示。
Command line instructions
Git global setup
git config --global user.name "<git user>"
git config --global user.email "git email"
Create a new repository
git clone <git 仓库地址>
cd git-demo
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder or Git repository
cd existing\_folder
git init
git remote add origin <git 仓库地址>
git add .
git commit
git push -u origin master
根据提示拉下来项目,之后使用idea打开项目,右下加显示目前分支

分支新建
点击后选择 new branch,输入develop,此时右下角显示目前分支已进入develop
之后如下图



Push之后你会发现在右下角 多出一个远端develop分支
分支提交
那么此时如果也要开发新功能,比如添加一个Dog'相关开发,那么你可以创建一个feature/dog分支并推入远端。创建新分支的流程和穿件develop分支流程相同
之后你需要在项目中添加一个dog.txt文件,此时项目结构如下

(.gitignore是git忽略设置文件,具体可百度如何设置)
之后提交分支,可以正项目提交,也可以在指定文件上面提交


注意,commit之后只是提交到了本地,需要push才是真正提交到了代码库,merge操作也是在本地操作,在push之后会在代码库中看到结果
分支合并
之后就feature分支开发完成后,要合并到develop分支.
- 先切到develop分支,
- 之后选择feature/dog分支进行merge
- merge完成后在进行push操作,

分支删除
之后确认完成后可以将已完成分支删除,同样在右下角分支管理中选择delete,远端分支不要删除


这里只是介绍了最简单的情况,分支更详细操作请参考一下两篇内容
还有关于拉去代码的git pull 和git fetch两个,目前建议用git fetch
http://blog.csdn.net/hudashi/article/details/7664457
在开发阶段应该避免分支交叉开发,容易产生混乱,日常开发应该保证分支清晰。再提交前请改重新查看自己代码是否正确,以免修改别人代码。