欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

git文件管理心得分享

程序员文章站 2023-11-16 09:15:04
untraked file 未跟踪的文件,通常为新建立的文件 traked file 通常为建立索引之后的文件 ignored 被忽略的文件,这类型的文件通常在...

untraked file 未跟踪的文件,通常为新建立的文件

traked file 通常为建立索引之后的文件

ignored 被忽略的文件,这类型的文件通常在一个文件列表中。维护这个列表的文件在版本库根目录名字为 .gitignore
初始化版本库,保证刚创建状态

huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ ls 
hello 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ ls -a 
./ ../ .git/ hello 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ rm -rf .git/ hello 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo 
$ git init 
initialized empty git repository in c:/users/huawei/desktop/git-repo/.git/ 

创建文件查看文件类型,发现为untraked file未被跟踪的文件

huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ echo "hello world" > hello 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ git status 
on branch master 
no commits yet 
untracked files: 
 (use "git add <file>..." to include in what will be committed) 
  hello 
nothing added to commit but untracked files present (use "git add" to track) 

被跟踪的文件通常为建立索引之后的文件,可以通过git ls-files -s查看。至于被忽略的文件可以看下面的演示,将文件名写入到.gitignore文件即可

huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ git status 
on branch master 
nothing to commit, working tree clean 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ echo "a" > a 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ git status 
on branch master 
untracked files: 
 (use "git add <file>..." to include in what will be committed) 
  a 
nothing added to commit but untracked files present (use "git add" to track) 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ echo a >> .gitignore 
huawei@desktop-jtc012c mingw64 ~/desktop/git-repo (master) 
$ git status 
on branch master 
untracked files: 
 (use "git add <file>..." to include in what will be committed) 
  .gitignore 
nothing added to commit but untracked files present (use "git add" to track) 

.gitignore文件语法

#开头的行用于注释

空行会被注释

目录名末尾用反斜线(/)标记

包含shell通配符,如*。例 debug/32bit/*.o

起始地感叹号用于取反模式