在git init上设置默认的目录结构 [英] Set up a default directory structure on git init
问题描述
我想通过在 git init
命令中自动创建.gitignore,README,LICENSE和其他文件来优化我的git工作流。
为此,我的 git init
的RTFM位于 http://git-scm.com/docs/git-init ,它告诉我执行以下操作之一:
- 使用
git init --template =< template_directory>
,但是很麻烦。 $ GIT_TEMPLATE_DIR环境变量的内容,但我宁愿不要。
- 设置
init.templatedir
配置变量。现在我们正在讨论!
所以我 和 sudo mkdir / usr / share / git-core / templates / my_template
和 touch
其中的一些文件,然后I vim〜/ .gitconfig
并追加:
$ $ p $ [init]
templatedir = / usr / share / git-core / templates / my_template
git config -l </ code>告诉我:
$ b $
...
init.templatedir = / usr / share / git-core / templates / my_template
...
对我自己感到高兴,我去了我的发展平台目录和:
$ git init
在/ the / current /目录中初始化的空Git存储库
$ ls -a
。 .. .git
无赖...文件在哪里? : 快速检查: 似乎 那么,我在这里做错了什么?错误的配置指令?错误的模板或其位置(我在OSX上)?模板应该是一个git repo吗?一个简单的吗? 看到是预期的 如果您正确阅读有关模板目录的手册:
$ b
$ ls -a / usr / share / git-core / templates / my_template
... ..gitignore LICENSE README.md
$ git --version
git version 1.8.2.1
$ git init --template = / usr / share / git-core / templates / my_template
也不起作用。
git
行为:
$ b
TEMPLATE DIRECTORY
模板目录包含文件和
目录,它们将在创建后复制到 $ GIT_DIR 。
从模板目录复制的文件放在 GIT_DIR
中,默认为 .git
目录在您的仓库根目录下。
git init
不支持据我所知,工作树。如果这种行为是必需的,你应该能够写出一些简单的bash别名或函数来为你做这件事。
I would like to optimise my git workflow by automating creation of .gitignore, README, LICENSE and other files on git init
command.
To do that I RTFM of git init
at http://git-scm.com/docs/git-init and it tells me to do one of the following:
- Use
git init --template=<template_directory>
, but it's bothersome. - Alter the contents of the $GIT_TEMPLATE_DIR environment variable, but I would rather not.
- Set the
init.templatedir
configuration variable. Now we're talking!
So I sudo mkdir /usr/share/git-core/templates/my_template
and touch
some files in it, then I vim ~/.gitconfig
and append:
[init]
templatedir = /usr/share/git-core/templates/my_template
And git config -l
tells me:
...
init.templatedir=/usr/share/git-core/templates/my_template
...
Happy with myself, I go to my development playground directory and:
$ git init
Initialized empty Git repository in /the/current/directory
$ ls -a
. .. .git
Bummer... where are the files? :(
Quick check:
$ ls -a /usr/share/git-core/templates/my_template
. .. .gitignore LICENSE README.md
$ git --version
git version 1.8.2.1
It seems that $ git init --template=/usr/share/git-core/templates/my_template
doesn't work either.
So what is it that I'm doing wrong here? Incorrect configuration directive? Bad template or its location (I'm on OSX)? Should template be a git repo? A bare one?
The behavior you're seeing is the expected git
behavior:
If you read the manual correctly about the template directory:
TEMPLATE DIRECTORY
The template directory contains files and directories that will be copied to the $GIT_DIR after it is created.
The files which are copied from the template directory are placed in your GIT_DIR
which defaults to the .git
directory under your repo's root directory.
git init
does not support templates for the work-tree as far as I know. If this behavior is required, you should be able to get away with writing some simple bash aliases or functions to do this for you.
这篇关于在git init上设置默认的目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!