最近在使用soureTree做代码git管理的时候出现了一个小插曲,暂且记录吧!
一.问题浮现
代码第一次提交时,可以看到,指定上传的文件只有一些资源性文件和可操作性的代码,编辑器的相应的文件都被忽略掉了

这个时候是编辑器中 .gitignore文件,也就是忽略文件作用的效果

但是,再第一次commit代码的时候,为了多人开发必须保证项目的完整性,所以一些编辑器文件也需改变,注意,此时要上传一些编辑器的文件,之后恰恰相反,也就是出现问题的场景原因。
1.找到忽略的代码,并提交

2.填写提交信息,这里直接推送到了远程orgin/maste上

3.提交后,第一次提交项目就算是结束了,刷新下远程库,可以看到代码已经在存在了

一直到这,应该说还算是很顺利的把本地代码用git托管到了远程库上
BUT
二.问题浮现
在MainActivity.java文件中简单添加一行测试方法methodTest();

此时按照设想,应该在soureTree中只提交改变MainActivity.java中的代码。
但是,很显眼的.idea 文件笔挺挺的在那晃呢?

不对啊!不是刚才已经忽略过了,这个时候怎么又不忽略了?目前怀疑是soureTree默认被选中过的忽略文件,在改变后默认不再被忽略,且入加入soureTree的缓存中,我就是被这缓存给坑的。
于是查资料,有人说是要在设置中,在soureTree的文件中,再添加相应的忽略属性。这里也说下吧,入口是 设置-> 高级

点编辑 这个 仓库指定忽略列表,写 /.idea/workspace.xml(这个是相对应的,因为此情景这个是个案例,其他文件一样添加即可),意思就是忽略.idea文件夹的workspace.xml文件

保存,心想着终于搞定了,于是刷新,不行,也有可能是我打开方式不对,关掉soureTree,重启,依然不行。

它还在那里嘲笑我看不惯它,又弄不死它的样子……
三,解决问题
想了好久,也查了好多,最后还是被soureTree的缓存给坑的。
上干货吧!
1.找到 soureTree中终端,打开输入 清楚文件夹指令:
git rm -r --cached .

2.然后输入:git add . ,此命令为添加更改变化
3.最后:”git commit -m”,此命令为添加更改变化!

搞完收工。
回过去看看

/.idea/workspace.xml 已经被忽略掉了,在忽略的文件中躺着呢

原文链接:https://blog.csdn.net/mijiaxiaojiu/article/details/81100376
网友评论