简体   繁体   English

从git隐藏文件-是否可以不添加到.gitignore?

[英]Hiding files from git— possible without adding to .gitignore?

I have a couple of files I've just added to a directory that's part of a git repo. 我有几个文件刚刚添加到git repo的目录中。 I'd like to hide them from the repo. 我想将它们隐藏在仓库中。

I could add them to .gitignore but is there another way? 我可以将它们添加到.gitignore,但是还有另一种方法吗? These are one-offs and it would be ideal if I could keep the .gitignore from having to list them. 这些是一次性的,如果我可以让.gitignore不必列出它们,那将是理想的选择。

You have many places to specify the ignored files. 您可以在许多地方指定忽略的文件。 See man gitignore for details: 有关详细信息,请参见man gitignore

  • .gitignore . .gitignore
  • $ XDG_CONFIG_HOME/git/ignore or whatever $GIT_DIR/info/exclude points to, if it exists. $ XDG_CONFIG_HOME/git/ignore$GIT_DIR/info/exclude指向的任何对象(如果存在)。
  • configuration variable core.excludesfile . 配置变量core.excludesfile Note that this option can be set globally or in the local copy of the project. 请注意,此选项可以全局设置,也可以在项目的本地副本中设置。
  • some low-level commands have a command line switch for that (but most usual commands do not). 一些低级命令为此使用了命令行开关(但是大多数常用命令没有)。

But note that, contrary to some other VCS, you can have one .gitignore on each directory of the project tree. 但是请注意,与其他一些VCS相反,您可以在项目树的每个目录上使用一个.gitignore Maybe your reticence to use the .gitignore is because you do not want to use the file in the root directory of your project. 您可能不愿意使用.gitignore是因为您不想使用项目根目录中的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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