簡體   English   中英

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文件寫入:

  • 跟蹤foo.sh和bar.yml
  • 而不是跟蹤所有gen___文件夾

我已經嘗試過了,但是不起作用(仍然跟蹤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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM