持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第6天,点击查看活动详情
一、bug出现端倪
我发现在IDEA项目中修改文件,commit没有检测到
改动API_interface下面所有文件全部不会检测到,我改动了Main,但是没有像.idea一样变色,在commit区也看不到它。
使用命令行的 git commit
报错
$ git commit -m "API commit"
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: API_Interface/src/main/java/com/example/api_interface/Service/Main.java
no changes added to commit (use "git add" and/or "git commit -a")
报错截图
二、解析原因
git status
查看状态
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: API_Interface/src/main/java/com/example/api_interface/Service/Main.java
no changes added to commit (use "git add" and/or "git commit -a")
备注:git status
输出的内容分为3个组
# On branch master
# Changes to be committed: (1.已经在stage区, 等待添加到HEAD中的文件)
# (use "git reset HEAD <file>..." to unstage)
#
#modified: hello.py
#
# Changes not staged for commit: (2.有修改, 但是没有被添加到stage区的文件)
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
#modified: main.py
#
# Untracked files:(3.没有tracked过的文件, 即从没有add过的文件)
# (use "git add <file>..." to include in what will be committed)
#
#hello.pyc
三、尝试解决
我猜测可能是git没追踪上的问题,按照提示就add一下,add完了,再commit,
第一次不报错,看起来像是成功的样子
git命令的成功push
试了下git status
不报错了,git push
也是成功的
但是IDEA里还是检测不到
IDEA软件git的检测bug依旧存在
很明显,这可能不是git追踪的问题,毕竟git push
都成功了。那我们看看追踪吧
git ls-tree -r master --name-only
为了实验严谨,再试一次 git push
git系统是能够看到成功push的
不要有侥幸心理了,这个文件是被追踪的,是一个我没见过的IDEA的bug。
问题描述:这个文件,被git追踪了,但是他的变化,IDEA里的git检测不到。
命令行是可以push的。但是,我不太习惯命令行,还是想搞好他。不过为了赶deadline先搞项目,抽空解决他。 更新:
四、发现IDEA的报错
具体原因
Invalid VCS root mapping(无效的版本管理系统根目录映射)
The directory <Project>\API_Interface is registered as a Git root, but no Git repositories were found there.
这个就是因为我在创建项目的时候勾了create git repository
后来我写了一半把所有.git
删了,但是这个目录还被注册为git 根目录的问题。
解决方法
点那个报错的Configure 配置下就好了,指箭头的删了他。
问题解决。
个人总结
只要用命令行
git add .
git commit -m "你的备注"
git push -u origin master
这个东西是没问题的,就是IDEA软件检测不到,不方便了点。
更新:
IDEA右下方的那个老给我提更新,我都没注意过。这次吸取教训,每一个error都值得我们认真对待。