2013-10-01 64 views

回答

2

但是,我不想推送的一個文件夾在其中有新文件時也會被推送。

假設您不想僅推送較新的文件,但想要跟蹤該目錄中較舊的文件,請將文件夾名稱添加到.gitignore

echo path/to/folder >> .gitignore 

如果要刪除該文件夾中的所有文件從跟蹤停下來,做一個額外的2個步驟

git rm -r --cached foldername 
git commit -m "removed previously tracked files" 
1

的文件夾添加到.gitignore作爲一款入門:yourfoldertoignore/

man gitignore

o If the pattern ends with a slash, it is removed for the purpose of 
     the following description, but it would only find a match with a 
     directory. In other words, foo/ will match a directory foo and 
     paths underneath it, but will not match a regular file or a 
     symbolic link foo (this is consistent with the way how pathspec 
     works in general in Git). 

如果你想在一段時間後推的文件夾,你將不得不使用--force開關添加任何東西在該目錄下。


此外,我強烈建議你不要推的東西盲目,(甚至沒有git add file.ext),而且還使用-p選項,以回顧一下你究竟要推(git add -p)。

1

請注意存在git add -u(僅對已修改的文件進行分階段處理)和git add -p,它們會在分段之前(在已修改的文件中)要求您進行每次更改。

還有-i;檢查full manual here

或者,你可以做git add .,它不會添加被忽略的文件(通過.gitignore忽略)。