Gitignore a file if file with different extension exists

后端 未结 2 1401
眼角桃花
眼角桃花 2020-12-17 22:25

In a project where for instance a parser is involved, some source code is the product of a program. For instance yacc generates - based on a .yy fi

相关标签:
2条回答
  • 2020-12-17 23:11

    My suggestion is create a script to update .gitignore. I don't know any, but you can look for a solution that runs this script automatically before a commit.

    Edit: I Googled and found this: https://github.com/observing/pre-commit - Probably needs some tests.

    0 讨论(0)
  • 2020-12-17 23:13

    I can see three ways to do this -- to answer the question directly, no, ignore processing consults only the pathname in question, not anything else about the environment.

    1. Put your generated source in a generated folder you ignore.

      Me, I like this one best, I know I'm in a minority but I don't like build detritus in my source directories.

    2. Have your makefile targets also update the .gitignore, with

      grep -qs ^target$ .gitignore || echo target >>.gitignore
      

      where target is the generated source file, as part of the recipe.

    3. put some marker in the generated filenames themselves, scanner.generated.c or something.

    For some reason I really dislike the pre-commit hook cleaning out unwanted source, git deleting things from a commit all by itself is just disturbing.

    0 讨论(0)
提交回复
热议问题