IDEA Tool Pit Avoidance Guide (10): After git pulls the java project, there are only .git and .idea files in the pulled project directory, no src or java directory | the pulled maven project is not recognized as a maven project

I. Introduction

Using the above title, I couldn't find a suitable solution. After reading many posts and repeated attempts, I came up with the following!

Note: The native IDEA version is 2019, other versions may be slightly different.

2. Error description

After pulling the project from git, the directory structure is as follows, missing the desired src directory

3. Expected effect

4. Reason Analysis

There may be many reasons, but the first thing that comes to mind should be that the pull project itself is this directory structure.

1) The currently pulled branch is the default branch, and other branches need to be pulled, such as master

At this point, you need to log in to the git remote warehouse to take a look (copy the http address of git to the browser address bar),

Verify the conjecture as shown in the figure above, the main branch does not have anything, and the required code cannot be pulled through git naturally.

2) Switch branches and verify the conjecture

At this point, it is enough to show that the default main branch was pulled just now, and the master branch is actually needed.

5. Solutions

Reminder: Choose Option 1 first!

Option One

As shown in the figure below, click the "Git:main" icon in the lower right corner of IDEA, click in turn: select origin/master (the branch you want) --> Checkout, wait a moment, close IDEA and open it again to see the complete directory , or enter the workspace where the project is located to see the complete directory.

Option II

Use the git clone command to operate

1) In the project directory under the workspace, open the cmd window and execute the following git command

2) git clone -b branch name git address

git clone -b master http://56.122.220.7/root/demo-java.git

third solution

1) Select VCS in the IDEA menu bar, and operate in sequence

VCS-->Git-->Pull-->A small pop-up window-->Under the Branches to merge: option, check the branch you want to pull-->click the pull below, and wait for a while under normal circumstances. .

不出意外的话,意外还是来了……

2)拉取失败,报refusing to merge错误

错误信息,如下图所示

Git pull failed

refusing to merge unrelated histories (拒绝合并不相关的历史)

3)解决方法

打开Terminal窗口,执行如下命令:

git pull origin master --allow-unrelated-histories

反之,如果在push的时候报refusing to merge unrelated histories (拒绝合并不相关的历史)

这个错误时,执行如下命令:

git push origin master --allow-unrelated-histories

至此,需要拉取的java代码就被拉取下来了

六、拓展

1)拉取的maven工程不被识别为maven项目

解决步骤:右键pom.xml 然后选择 【Add as Maven Project】 之后就会当成maven项目。

2)从git拉取SpringBoot项目后,大量爆红,不能启动,不识别依赖包

解决方案:点击进入

七、鸣谢

https://blog.csdn.net/u011723409/article/details/125058172
这篇帖子,帮我解决了拉取分支的问题
https://blog.csdn.net/ZCaesarK/article/details/125316158
这篇贴,帮我解决了pull报错的问题

八、总结

本文重点介绍了,解决使用git工具在IDEA拉取java代码后,拉取不到src目录,看不到java代码的问题。究其原因,只因拉取的分支不对,重点介绍了拉取想要分支的步骤。

九、尾言

在解决该问题过程中,没遇到合适帖子,可以一步到位解决该问题,固有此贴,希望你有所帮助。
注:导致该问题的原因,可能还有其他种情况,只是暂时没遇到,必要的时候,会继续更新。。

如果你觉得本帖对你有帮助,还不错,欢迎点赞、评论,感谢支持,共渡难关!

十、附注

猜你可能喜欢

1、IDEA工具避坑指南(一):新导入工程后,不能创建Class和package

2、IDEA工具避坑指南(二):导入Maven工程后,不显示Maven侧边栏

3、IDEA工具避坑指南(三):项目运行时,提示JDK版本过低,需要更换版本

4、IDEA工具避坑指南(四):如何隐藏不需要的后缀文件(优化篇)

5、IDEA工具避坑指南(五):如何统一编码为UTF-8(优化篇)

6、IDEA工具避坑指南(十一):git导入SpringBoot后|不识别依赖 |大量爆红 | 无法启动

Guess you like

Origin blog.csdn.net/xp871038951/article/details/129764729