更新gitignore后如何使其生效

  git rm --cached --force -r  .

 

Files already tracked by Git are not affected; 

Git - gitignore Documentation https://git-scm.com/docs/gitignore

gitignore - Specifies intentionally untracked files to ignore

 

NOTES

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.

To stop tracking a file that is currently tracked, use git rm --cached.

 
 

更新gitignore后如何使其生效_Falcon2000的专栏-CSDN博客 https://blog.csdn.net/Falcon2000/article/details/82830639

我们应该先把本地的缓存删除,然后再进行push,操作步骤如下

  1.  
    git rm -r --cached . // 删除本地缓存
  2.  
    git add . // 添加要提交的文件
  3.  

 

 【实践出真知】

注意,上述会导致提交后的diff变动为与clone本地文件时的commentId 做比较

例如

git clone -b test url

git log commentId01 

本地先后提交了02,03,04,05;

在提交06前执行了 git rm -r --cached .  会导致 push 06后,diff是相对01的,而非相对05的;虽然提交的内容确实是06下的内容。

 

[git] 如何解决修改了.gitignore却不生效 - 简书 https://www.jianshu.com/p/6d06583c536c

1、问题描述:

在使用git时,想忽略某些不想提交的文件,可以在项目中修改.gitignore文件,如果没有这个文件,可以手动建一个。但是常常发现修改后,点击提交,发现没有生效。

2、原因分析:

因为.gitignore只能忽略那些原来没有被track过的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。解决方法就是先把本地缓存删除(改变成未track状态),然后再提交。

3、解决办法:

在所在的库逐次执行下面命令:

git rm --cached --force "file-to-path"
git rm --cached --force "file2-to-path"
...

 

git ignore 语法

注意*的误用

 

# The slash / is used as the directory separator. Separators may occur at the beginning, middle or end of the .gitignore search pattern.

# If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.

# An asterisk "*" matches anything except a slash. The character "?" matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.
# A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".
/src/app/settings_conf/local.py

https://git-scm.com/docs/gitignore

 

 

不同语言 gitignore文件

https://github.com/github/gitignore/blob/main/Go.gitignore
https://github.com/github/gitignore/blob/main/Java.gitignore


 
 

 

posted @   papering  阅读(1728)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-03-28 怎么表示自然数 陶哲轩
2019-03-28 Shell实现判断进程是否存在并重新启动脚本
2017-03-28 数据总线和流计算在城市大脑中的应用
2017-03-28 无推荐不APP
2017-03-28 ww
2017-03-28 单集群服务器数量
2017-03-28 高并发访问,低延迟控制
点击右上角即可分享
微信分享提示