Please pls help me write my ignore

Please pls help me write my ignore

// ignore all directories except for above
*

// do not exclude txt
(?i)!**.{md,txt}

// ignore .trash
.trash

This doesn’t ignore anything, and I’m not sure which part went wrong

My goal:

  • sync only text file (except for text file in .trash)
  • do not sync anything in .trash

thanks a great lot in advance

The order does matter, so you probably want:

// do not exclude txt
(?i)!*.{md,txt}

// ignore all directories except for above
*

The two ** are also redundant. They are only needed when you have patterns like directory/*/file and directory/**/file, which will match different contents. In addition, * already matches everything, so there is no need for a separate .trash entry above it.

thank you so much! But I realize I made a mistake in my post. What I actually meant is

My goal:

  • sync only text file (but not the text file in .trash)
  • do not sync anything in .trash

This ignore provided seems to sync the text file in my .trash, which is not what I wanted.

// do not exclude txt
(?i)!*.{md,txt}

// ignore all directories except for above
*

Could you also explain how order matters in ignore? I can’t seem to find it in the official document

@tomasz86

Basically, if a previous patterns matches something already, then you cannot “unignore” it afterwards. This is why if you put * first, then everything gets ignored at the very beginning and you’ve got nothing to work with anymore.

Taking .trash into account, you probably want this then:

// ignore .trash
.trash

// do not ignore md and txt
(?i)!*.{md,txt}

// ignore all except for above
*
2 Likes

thanks a lot! @tomasz86

The second sentence in that paragraph tells you the order is important.

The first pattern that matches will decide the fate of a given file.

This sentence?

Think of an Ignore Pattern as being like an access list in this regard:

The file is evaluated by the first line in the Ignore Pattern. If there’s a match (whether it’s to ignore or to unignore), the action is taken and the ignore process exits: in other words, further lines in the Ignore Pattern file are not evaluated for that file.

This continues, line by line, until there is a match. The action is taken and further lines are not evaluated.

The final, “implied” line of the Ignore Pattern is to allow everything.

2 Likes

thanks a lot!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.