- IntelliJ IDEA->Performance->Version Control->git 将自己安装git的可执行文件路径填入Path to Git executable,点击 Test测试一下
二、上传项目到git仓库
在你的idea里新建git仓库,这是新建本地仓库,等会会同步到线上git仓库

新建后如果代码不是文件名不是绿色的表示没有加入到git索引中
将需要上传的文件按照下图方式add

添加后,相应的文件名会变成绿色
然后commit项目,提交项目,

这里是先提交带本地仓库,然后push到线上仓库。注意这里和svn不一样。
这里一定要选择commit and push .(先提交带本地仓库,然后push到线上仓库)
三、从git仓库检出项目
选择checkout

四、更新项目、解决冲突
按照图片中的步骤,顺序不能乱,先stash,然后pull,最后unstash

stash会让你输入标记名称,unstash的时候选择想要的标记

如果代码有冲突,我们需要编辑冲突,我们一般选择merge,就是合并的意思,当然你也可以不合并直接使用线上的或者暂存里的代码。

合并代码的时候,图片中描述了,三屏分别对应的是什么。

五、切换git分支
右下角有个当前分支名称,点击会谈出一分支信息。如果你想切换分支,选中分支,点击右键checkout即可。

六 、Git 冲突:Your local changes would be overwritten by merge. Commit, stash or revert them to proceed.
解决办法 https://blog.csdn.net/nan7_/article/details/25624637
七、idea中git回退本地仓库版本
场景:代码commit到本地仓库,还没有push到远程仓库,这时要回退代码。
介绍下Reset Head中三种Reset Type类型:
1.Mixed(默认):它回退到某个版本,本地会保留源码,回退commit和index信息,若要提交重新commit。
2.soft: 回退到某个版本,只回退了commit的信息,不会恢复到index file一级,若要提交重新commit。
3.Hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容。
操作如下:
拿ConfigServerApplication类中的fun() 方法来验证,每次提交修改方法中的数据,目前本地仓库的记录是10,远程仓库的记录是8,如下:
网友评论