英文:
Why is an entity file not visible in Spring Tool Suite 4?
问题
我正在使用Java Spring Boot进行开发,有一天我意识到其中一个实体消失了。
如您所见,在com.example.demo.entity
包中有一个名为Report.java
的文件,但最初也有一个名为User.java
的文件。
因为起初我以为User.java
已经不存在了,所以我尝试再次通过右键点击实体包并选择“创建新类”来创建该文件。
但是,当我尝试将文件命名为User时,系统不允许我创建相同名称的文件。我收到了一个错误消息“存在同名但大小写不同的类型。”
我觉得这很奇怪,于是我在GitBash中尝试了ls命令
,然后似乎User.java
仍然存在。
但然后问题又回到了最初。为什么我不能在Spring Tool Suite中看到User.java
文件,就像第一个附图中显示的那样呢?
我想知道这是否与另一个分支有关。我目前正在进行的项目是一个学校项目,我有两个git账户。一个是学校提供的Git账户,另一个是我个人的GitHub账户。
起初,我想只使用我的学校Git账户来开发项目,但由于某种原因,git pull命令无法正常工作,老师也不知道原因,无法修复。老师告诉我,他可以看到我提交和推送的所有文件和文件夹,所以至少我知道提交和推送在我的学校Git账户上是有效的。因为在学校Git上的最终提交被视为作业的“提交”,所以我必须使用学校Git账户。
由于我希望为我已完成一半的项目(甚至是完成后的完整项目)创建一个备份,我决定同时使用我的学校Git账户和我的个人GitHub账户。因此,每次我提交和推送时都会经过以下流程。
-> 提交并推送到我的学校Git账户(main分支)
-> 从我的学校Git账户(main分支)切换到我的个人Git账户(master分支)
-> 将远程URL从我的学校Git账户切换到我的个人Git账户
-> 提交并推送到我的个人GitHub账户(master分支)
-> 切换回我的学校Git账户的分支和远程URL
我记得上次我尝试从我的学校Git账户切换回我的个人Git账户时,GitBash不允许我切换,给了我一个错误消息,类似于“除非删除或重新定位User.java文件,否则无法切换回主分支,否则文件将被覆盖”
之类的。
因为User.java
文件的内容相当简单,并且我在我的Google文档中备份了一个副本,所以我只是删除了User.java
文件,以便能够快速解决问题,从而可以切换回主分支。
也许问题是我在切换回主分支之前(学校Git)删除了主分支(个人Git)中的User.java
文件?但如果是这样,我应该做些什么呢?现在又该怎么办呢?如何修复,以便在Spring Tool Suite的主分支中再次看到User.java
文件?
顺便说一下,我使用的操作系统是Windows 10。
我在学校Git上进行了最终提交,项目本身已经完成,所以作业本身是没问题的,但我想在我的个人GitHub账户上也保存这个项目的备份,因为在我从学校毕业后,我将失去学校Git账户,并且不能再访问项目的最新版本...我想在网上备份我的项目。我还想更好地理解Git的工作原理。
英文:
I'm working on Java Spring Boot, and one day I realized that one of the entities was missing.
As you can see, there is a file named Report.java
in the com.example.demo.entity
package, but there was originally User.java
file as well.
Because I thought that the User.java was gone at first, I tried to create the file once again by right clicking the entity package and choosing “create a new class”.
But when I try to name the file as User, I’m not allowed to create the file with the same name. I get an error message “Type with same name but different case exists.”
I thought it was strange, so I tried ls command
in GitBash, and then it seemed that the User.java
still does exist.
But then again it comes back to the first question. Why can’t I see the User.java
file in Spring Tool Suite, as shown in the first attached image?
I wonder if this has something to do with the other branch. The project I’m currently working on is a school project, and I have 2 git accounts. One is a Git account provided by the school and the other one is my personal GitHub account.
At first I thought of working on the project only with my school git account, but for some reason git pull was not properly working, and the teacher was not sure why and couldn’t fix it either. The teacher told me that he could see all the folders and files that I committed and pushed, so at least I know that commit and push are working on my school git account. Because the final commit on the school git is considered to be a “submission” of the assignment, I must use the school git account.
As I wanted a backup for my half-complete project (and even for the complete one once it’s finished), I decided to use both of my school git account and my personal GitHub account at the same time. So it went through the following process every time I committed and pushed.
-> commit and push to my school git (main-branch)
-> switch the branch from my school git (main-branch) to my personal git (master)
-> switch the remote’s URL from my school git to my personal git
-> commit and push to my personal GitHub account (master)
-> switch back to my school git’s branch and remote’s URL
I remember that the last time I tried to switch back from my school git to my personal Git, the GitBash didn’t let me switch, giving me an error message like “You can’t switch back to the master unless you remove or relocate User.java file, otherwise the files will be overwritten”
or something like that.
Because the User.java
file’s content was rather simple and I made a backup in my Google document, I just deleted the User.java file as a quick solution so that I could switch back to the master branch.
Maybe the problem was that I deleted the User.java file in the main-branch branch (school) before switching back to master branch (personal)? But if so, what should I have done instead? And what now? How should I fix it so that User.java file will be visible again on my master branch in Spring Tool Suite?
By the way, the OS that I'm using is Windows 10.
I made the final commit on the school git and the project itself is complete, so the assignment itself is fine, but I want to save the project on my personal GitHub account as well, because after I graduate from the school I will lose my school git account and no longer have an access to the latest version of the project…. I want to make a backup of my project available online as well. I also want to understand how Git works better.
专注分享java语言的经验与见解,让所有开发者获益!
评论