简体   繁体   中英

Conditional .gitignore files - adding logic to .gitignore

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

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM