开始的时候 ,所有文件都是untracked(不被追踪的)。如果执行 “git status”指令,Git 会列出 untracked 文件列表。
在正常情况下,文件夹中的所有文件应该被分类成tracked(被追踪的)和ignored(忽略的)。
tracked状态的文件就是已经加入Git 文档库的文件。要让文件变成ignored状态(也就是让 Git 不要检查这个文件),
必须现在文件夹中创建一个名为 “ 。gitignored” 的文件,然后把要忽略的文件逐一列在这个文件中(一个文件一行)。
下面试手小例子:
------------------------------------------------------------------------------------
//先进入个文件夹。
[email protected] MINGW64 ~
$ cd "f:/dome"
[email protected] MINGW64 /f/dome
$ git init
Initialized empty Git repository in F:/dome/.git/
--------------------------------------------------------------------------------------
//输入指令:git status后显示出不被追踪的文件名称(共3个,folder/ 、poem1和poem2)
[email protected] MINGW64 /f/dome (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
folder/
poem1.txt
poem2.txt
nothing added to commit but untracked files present (use "git add" to track)
----------------------------------------------------------------------------------------------------
//把 poem1 加入Git文档库中(之后它就成为被追踪状态)
[email protected] MINGW64 /f/dome (master)
$ git add poem1.txt
[email protected] MINGW64 /f/dome (master)
$ git commit -m ‘1st commit‘
[master (root-commit) 1ea43d9] 1st commit
1 file changed, 2 insertions(+)
create mode 100644 poem1.txt
-----------------------------------------------------------------------------------------------------
//创建名为 “ .gitignored” 的文件(是一个txt文件之后在里面写上 folder 和它本身的文件名.gitignored)
[email protected] MINGW64 /f/dome (master)
$ touch .gitignore
----------------------------------------------------------------------------------------------------------
//之后就会看到untracked 的文件就只有poem2了,poem1被存入文件库(被追踪),其他的则被忽略。
[email protected] MINGW64 /f/dome (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: poem1.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
poem2.txt
no changes added to commit (use "git add" and/or "git commit -a")
------------------------------------------------------------------------------------------------------------