Domanda

I'm creating my dotfiles and using oh my zsh. It creates a directory called .oh-my-zsh in my home directory.

I want to ignore everything inside .oh-my-zsh, except the custom/ directory. However, custom/ has the file example.zsh and a directory called example/, which contains the file example.plugin.zsh, and I also want to ignore them.

To make it clearer, the structure can be thought as this:

.oh-my-zsh/
  custom/
    my-folder-to-be-kept/
      ..
    example/
      example.plugin.zsh
    example.zsh
  lib/
  log/
  ...

I have a .gitignore in my home directory:

/.oh-my-zsh/*
!/.oh-my-zsh/custom/
/.oh-my-zsh/custom/example.zsh
/.oh-my-zsh/custom/example/example.plugin.zsh

However, there's a .gitignore file inside .oh-my-zsh, which contains the follow content:

locals.zsh
log/.zsh_history
projects.zsh
custom/*
!custom/example
!custom/example.zsh
*.swp
!custom/example.zshcache
cache/

When I add the untracked files, example.plugin.zsh is ignored, but example.zsh isn't. Therefore, I think I'd have to ignore that .gitignore inside .oh-my-zsh so that my .gitignore can work, because !custom/example.zsh is conflicting.

È stato utile?

Soluzione

Taken from the help of git

Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.

As your "sub .gitignore" file will override the .gitignore located in root your question should actually be

Can I make a .gitignore file to have no effect?

And the answer is no. There are ways to ignore a .gitignore file but this will only avoid the file to be commited while it will still be affecting what has to be ignored or not.

As a rule of thumb it is a bad habit to have multiple .gitignore within a project. In your case I would try to modify the content of the generated .gitignore to avoid the problem or directly the way it is generated. Your case sounds pretty strange and I think you are doing something wrong or that could be done better. You should maybe think about it again and restructure your concept. Any other solution will be just a work around

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top