Reputation: 100270
So I have TypeScript project. The generated .d.ts and .js files can cause unnecessary merge conflicts.
However, this project is big and is currently only ~50% converted from JS to TS, so I cannot simply .gitignore all .js files. Furthermore, there are some .js files which I will never convert to .ts.
So is there a way to conditionally ignore a file?
The logic is of course simple:
ignore z.js if z.ts exists
Upvotes: 1
Views: 1993
Reputation: 391596
You can have multiple .gitignore
files. If all your typescript files are in one directory (or one directory structure) and your .js
files are in another, place a new .gitignore
file inside the typescript directory that ignores javascript files.
This will only ignore javascript files in that directory and subdirectories.
Upvotes: 2
Reputation: 32504
So is there a way to conditionally ignore a file?
No, there isn't.
However, this project is big and is currently only ~50% converted from JS to TS, so I cannot simply .gitignore all .js files
You can. Files already tracked by Git are not affected by .gitignore
, thus only *.js
files generated by the build process will be ignored.
Upvotes: 4
Reputation: 1025
This is not possible, .gitignore
is a very simple file and it doesn't allow any conditional rules for ignoring file(s) or folder(s).
However, you can create different patterns to include or exclude your file(s).
Please Take a look here for help on writing .gitignore
patterns: .gitignore File Docs
Upvotes: 2