更新gitignore后如何使其生效


 

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM