先总结一下
方法 |
好处 |
劣势 |
通过intellij idea的git组件 |
项目中有修改之后的显示 |
鼠标流+命令行操作,比较复杂 |
通过git命令行 |
全部命令行操作,指令清晰 |
由于没有纳入到intellij idea的git组件的管理,所以没有颜色提示这些,需要自己来配置下 |
方法1:通过intellij idea的git组件
首先选中要export to gitee的module,然后VCS,import into Version Control,Create Git Repository
之后先add,再commit。注意,在add之后,要删除掉无用的工程文件,比如从eclipse导入之后遗留的.setting文件夹,.classpath及.project文件。
之后在码云上创建了一个项目,注意,有没有md文件这里,如果创建了md文件,那么后面提交就会麻烦一些。
之后,在intellij idea中
这里定义一个remote,选择SSH的
之后push,报错
Push rejected: eureka-server: push to eshop-eureka-server-origin/master was rejected
为啥呢?
原因是我们remote gitee有一个md文件,需要先更新gitee上的md文件,然后才能提交。
好,那先pull一下
结果还是报错:fatal: refusing to merge unrelated histories
参考:git无法pull仓库refusing to merge unrelated histories
结果
E:\develop_IJ\spring_cloud_demo\eureka-server>git pull eshop-eureka-server-origin master --a
llow-unrelated-histories
From gitee.com:constfafa/eshop-eureka-server
* branch master -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
.classpath
Please commit your changes or stash them before you merge.
Aborting
也就是说我们add和commit的文件要一致,如果有文件add了但没有commit,说明没啥用,那就删除掉。
最后
成功pull下来README.md
也正常push了
以上是通过intellij idea提供的git支持来做的,也可以直接在terminal中通过git语法来做
以上过程其实更加简单,而且更清晰
方法2:使用intellij idea的terminal通过git命令行
1. 在gitee上new repository,其中包含了.gitignore以及Readme.md
https://gitee.com/constfafa/eshop-product-service
2. 执行git init,将当前intellij idea module加入git管理
3. 给git添加远程仓库
git remote add origin [email protected]:constfafa/eshop-product-service.git
4. 从远程仓库中拉取.gitignore以及Readme.md文件
git pull origin master --allow-unrelated-histories
5. 将当前项目加入git暂存区
6. 将当前项目提交到本地 git commit –m “local commit”
7. 将项目push到远程仓库
这样,通过git pull和git push就实现了本地intellij module和远程gitee仓库的交互了
但这样也有一个不好的地方,那就是由于没有加入到intellij idea的git组件管理中,导致无法享受颜色提示,怎么办呢?
当我们重新导入添加了git的项目后,intellij idea会在event log中提示
让我们在settings中加入管理
点击Add root,就可以了
如果点击configure
那么就进入到