git - 在 git init 上设置默认目录结构

标签 git templates

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

为此,我使用了 git init 的 RTFM在 http://git-scm.com/docs/git-init它告诉我执行以下操作之一:

  1. 使用git init --template=<template_directory> ,但这很麻烦。
  2. 更改 $GIT_TEMPLATE_DIR 环境变量的内容,但我不想这样做。
  3. 设置init.templatedir配置变量。现在我们开始谈了!

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

[init]
    templatedir = /usr/share/git-core/templates/my_template

git config -l告诉我:

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

对自己很满意,我转到我的开发 Playground 目录并:

$ 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 吗?光秃秃的?

最佳答案

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

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

TEMPLATE DIRECTORY

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

从模板目录复制的文件放置在您的 GIT_DIR 中,默认为您的存储库根目录下的 .git 目录。

据我所知,

git init 不支持工作树模板。如果需要这种行为,您应该能够编写一些简单的 bash 别名或函数来为您完成这项工作。

关于git - 在 git init 上设置默认目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16363460/

相关文章:

git - 从 gitlab 推送到远程 git 服务器时为 "Connection refused - connect(2) (Errno::ECONNREFUSED)"

c++ - 显式默认模板化构造函数

git - 设置 git 以要求 ssh key 文件

Git - 从以前的提交分支和拆分提交历史

git - 当我使用 git stash 时,我最终会得到 <<<<<<< 更新的上游和文件中的其他内容

git - GWT 源代码 repo - GIT 和 SVN - 跟踪更改的是哪个?

c++ - 如何将枚举模板映射到类型模板?

php - 是否可以在 Silverstripe 模板变量上运行一个函数来格式化输出?

c++ - "unspecialized class template can' t be used as a template argument”是什么意思?

C++:如何防止模板专门化指针?