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.
我们应该先把本地的缓存删除,然后再进行push,操作步骤如下
-
git rm -r --cached . // 删除本地缓存 -
git add . // 添加要提交的文件
【实践出真知】
注意,上述会导致提交后的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却不生效 -
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