![](/img/trans.png)
[英]How do I ignore a certain file type in a certain directory and its sub-directory in Git?
[英]git ignore certain sub directory / folder and its content
我有以下目錄結構:
ls -l experiment/
foo.sh
gen__20190425_144843
gen__20190425_144854
bar.yml
其中gen___是文件夾。
如何將.gitignore文件寫入:
我已經嘗試過了,但是不起作用(仍然跟蹤gen文件夾)
./experiment/gen__*/*
!./experiment/foo.sh
!./experiment/bar.yml
如評論所示,我最終使用以下內容:
experiment/gen__*/*
!experiment/foo.sh
!experiment/bar.yml
重要的是使用裸目錄名稱 :
experiment/
./experiment/
如下面的示例所示, experiment/gen__*
應該足夠了:
~$ mkdir test
~$ cd test
~/test$ git init
Initialized empty Git repository in /home/mh/test/.git/
~/test$ touch foo.sh
~/test$ touch bar.yml
~/test$ mkdir gen__20190425_144843
~/test$ touch gen__20190425_144843/1
~/test$ touch gen__20190425_144843/2
~/test$ mkdir gen__20190425_144854
~/test$ touch gen__20190425_144854/3
~/test$ touch gen__20190425_144854/4
~/test$ tree
.
├── bar.yml
├── foo.sh
├── gen__20190425_144843
│ ├── 1
│ └── 2
└── gen__20190425_144854
├── 3
└── 4
2 directories, 6 files
~/test$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
bar.yml
foo.sh
gen__20190425_144843/
gen__20190425_144854/
nothing added to commit but untracked files present (use "git add" to track)
~/test$ echo "gen__*" > .gitignore
~/test$ cat .gitignore
gen__*
~/test$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
bar.yml
foo.sh
nothing added to commit but untracked files present (use "git add" to track)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.