Git ignore rules (.gitignore configuration) does not take effect causes and solutions

Reference article: https://www.cnblogs.com/kevingrace/p/5690241.html

第一种方法:

.gitignore中已经标明忽略的文件目录下的文件,git push的时候还会出现在push的目录中,或者用git status查看状态,想要忽略的文件还是显示被追踪状态。
原因是因为在git忽略目录中,新建的文件在git中会有缓存,如果某些文件已经被纳入了版本管理中,就算是在.gitignore中已经声明了忽略路径也是不起作用的,
这时候我们就应该先把本地缓存删除,然后再进行git的提交,这样就不会出现忽略的文件了。
  
解决方法: git清除本地缓存(改变成未track状态),然后再提交:
[root@kevin ~] # git rm -r --cached .
[root@kevin ~] # git add .
[root@kevin ~] # git commit -m 'update .gitignore'
[root@kevin ~] # git push -u origin master
 
需要特别注意的是:
1).gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
2)想要.gitignore起作用,必须要在这些文件不在暂存区中才可以,.gitignore文件只是忽略没有被staged(cached)文件,
    对于已经被staged文件,加入ignore文件时一定要先从staged移除,才可以忽略。
 
第二种方法:(推荐)
在每个clone下来的仓库中手动设置不要检查特定文件的更改情况。
[root@kevin ~] # git update-index --assume-unchanged PATH                  //在PATH处输入要忽略的文件
 

How to delete a remote repository such files previously uploaded files after use .gitignore keep local files
when using git and github, and before did not write .gitignore file, you do not need to upload some files, with the addition of .gitignore after the file, you wanted to delete files in the remote repository, but want to save the file locally. This time not directly use the "git RM Directory" , this will delete the local file repository. You can use " git RM -r -cached Directory " to remove the buffer, then " the commit " and " the Push ", it will find a remote repository unnecessary file is deleted, then you can directly use the " git the Add -A " modified to add content, upload files would be bound by the content .gitignore file.

Additional Description: File git libraries are located in the folder roughly four states

Untracked:

未跟踪, 此文件在文件夹中, 但并没有加入到git库, 不参与版本控制. 通过git add 状态变为Staged.
 
Unmodify:
文件已经入库, 未修改, 即版本库中的文件快照内容与文件夹中完全一致. 这种类型的文件有两种去处, 如果它被修改,
而变为Modified. 如果使用git  rm 移出版本库, 则成为Untracked文件
 
Modified:
文件已修改, 仅仅是修改, 并没有进行其他的操作. 这个文件也有两个去处, 通过git add可进入暂存staged状态,
使用git checkout 则丢弃修改过, 返回到unmodify状态, 这个git checkout即从库中取出文件, 覆盖当前修改
 
Staged:
暂存状态. 执行git commit则将修改同步到库中, 这时库中的文件和本地文件又变为一致, 文件为Unmodify状态.
执行git reset HEAD filename取消暂存, 文件状态为Modified
 
Git 状态 untracked 和 not staged的区别
1)untrack     表示是新文件,没有被add过,是为跟踪的意思。
2)not staged  表示add过的文件,即跟踪文件,再次修改没有add,就是没有暂存的意思

Guess you like

Origin www.cnblogs.com/rainbowk/p/10932322.html