Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
973 views
in Technique[技术] by (71.8m points)

version control - How do you make Git ignore files without using .gitignore?

Due to external weird constraints I cannot modify the .gitignore of my repository. Is there a way to ignore files and directories other than modifying a .gitignore? Even if it is a global solution like a global configuration that will be applied to all my repositories.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do not forget, according to gitignore, that there is an order of precedence in the different "ignore pattern sources" that Git consider:

  • Patterns read from the command line for those commands that support them.
  • 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 root) being overridden by those in lower level files down to the directory containing the file.
  • Patterns read from $GIT_DIR/info/exclude.
  • Patterns read from the file specified by the configuration variable core.excludesfile.

The last two can be a solution for your problem but:

  • they are not replicated for a distant repository
  • they can have their patterns overridden by the other sources

(See also this SO question)


The other two solutions involve updating the index (git update-index):

However, when you checkout another branch or when you git pull, that "ignore" status might be reset. Hence the other option:

The difference between the two is explained in "Git - Difference Between 'assume-unchanged' and 'skip-worktree'".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...