在git init中自动添加.gitignore和钩子 [英] Automatically add .gitignore and hooks on git init

查看:533
本文介绍了在git init中自动添加.gitignore和钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法告诉git每次在特定的机器上运行 git init 时,自动创建/填充.gitignore和.git / hooks文件夹中的某些文件?也许是某个地方的全局配置?

Is there a way to tell git to automatically create/populate .gitignore and certain files in the .git/hooks folder every time git init is run on a certain machine? Maybe a global config somewhere?

我们有需要忽略的符号链接,以及需要设置的预接收和接收后挂接对于每一个回购,所以这将比手动为每个回购更容易。

We have symlinks that need to be ignored across the board, as well as pre-receive and post-receive hooks that need to be set up for every repo, so this would be easier than doing it manually for each one.

谢谢。

推荐答案

您可以使用git模板目录来实现此目的。

You can achieve this using a git template directory

git config --global init.templatedir /path/to/template

然后,您可以将文件添加到文件夹 /它们将自动复制到 git init 目录下的 .git / hooks / code>

You can then add files to the folder /path/to/template/hooks and they will be automatically copied to the .git/hooks folder on git init

您可以将您需要的.gitignore内容放入名为 exclude 的文件中文件夹 / path / to / template / info 。然后,它将在由 git init

You can place the .gitignore contents you want in a file you name exclude in the folder /path/to/template/info. Then it will effectively be a .gitignore file in all new repositories created by git init

如果你在unix上,甚至有一个默认模板目录 / usr / share / git-core / templates

If you are on unix, there is even a default template directory /usr/share/git-core/templates

这篇关于在git init中自动添加.gitignore和钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆