在 git init 上设置默认目录结构 [英] Set up a default directory structure on git init

查看:14
本文介绍了在 git init 上设置默认目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过在 git init 命令上自动创建 .gitignore、README、LICENSE 和其他文件来优化我的 git 工作流程.

I would like to optimise my git workflow by automating creation of .gitignore, README, LICENSE and other files on git init command.

要做到这一点,我在 http://git init 的 RTFMgit-scm.com/docs/git-init 并告诉我执行以下操作之一:

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:

  1. 使用git init --template=,但是很麻烦.
  2. 更改 $GIT_TEMPLATE_DIR 环境变量的内容,但我不想这样做.
  3. 设置 init.templatedir 配置变量.现在我们在说话!
  1. Use git init --template=<template_directory>, but it's bothersome.
  2. Alter the contents of the $GIT_TEMPLATE_DIR environment variable, but I would rather not.
  3. Set the init.templatedir configuration variable. Now we're talking!

所以我 sudo mkdir/usr/share/git-core/templates/my_templatetouch 里面的一些文件,然后我 vim ~/.gitconfig 并附加:

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

而且 git config -l 告诉我:

...
init.templatedir=/usr/share/git-core/templates/my_template
...

...
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

糟糕……文件在哪里?:(

快速检查:

$ 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 也不起作用.

那么我在这里做错了什么?配置指令不正确?错误的模板或其位置(我在 OSX 上)?模板应该是 git repo 吗?光秃秃的?

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?

推荐答案

您看到的行为是预期的 git 行为:

The behavior you're seeing is the expected git behavior:

如果您正确阅读了有关模板目录的手册:

If you read the manual correctly about the template directory:

模板目录

模板目录包含文件和创建后将复制到 $GIT_DIR 的目录.

The template directory contains files and directories that will be copied to the $GIT_DIR after it is created.

从模板目录复制的文件放在你的 GIT_DIR 中,它默认在你的 repo 根目录下的 .git 目录中.

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 不支持工作树的模板.如果需要这种行为,您应该能够避免编写一些简单的 bash 别名或函数来为您执行此操作.

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屋!

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