我正在尝试将单个非跟踪文件添加到位于其中的目录中的存储库中.gitignore.
我使用以下内容:
parent/child/*
parent/child/child-02/*
!parent/child/child-02/file.txt
Run Code Online (Sandbox Code Playgroud)
这通常适用于第一个子目录,但不适用于上述格式.我错过了什么?
一种方法是强制添加单个文件.一旦跟踪,git将继续跟踪文件,无论是否在您的任何文件中被忽略.gitignore.
所以简单地使用以下将工作:
git add -f parent/child/child-02/file.txt
git commit -m "added file.txt"
Run Code Online (Sandbox Code Playgroud)
如果您确实想要更正.gitignore文件,则必须再添加一条规则(!parent/child/child-02).这基本上告诉git不要忽略child-02目录,因此后续规则有效:
parent/child/*
!parent/child/child-02
parent/child/child-02/*
!parent/child/child-02/file.txt
Run Code Online (Sandbox Code Playgroud)
DEMO
test $ mkdir repo && cd repo && git init
repo $ mkdir -p parent/child/child-02
repo $ touch file parent/file parent/child/file parent/child/child-02/file.txt
repo $ cat .gitignore
parent/child/*
!parent/child/child-02
parent/child/child-02/*
!parent/child/child-02/file.txt
repo $ git add .
repo $ git status
new file: .gitignore
new file: file
new file: parent/child/child-02/file.txt
new file: parent/file
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
927 次 |
| 最近记录: |