安装git出现templates not found的问题

时间:2022-04-24
本文章向大家介绍安装git出现templates not found的问题,主要内容包括背景、操作流程重现、解决思路、思考、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

背景

goods.api需要在新机器上部署,该机器上没有安装git,需要安装git,查询git版本为2.4.5-1.el6 ,使用yum 一顿安装后,执行git clone命令告知warning: templates not found /usr/local/test-git/share/git-core/templates ,导致无法拉取代码下来

操作流程重现

1、执行 yum list | grep ^git  查看git版本

2、执行yum install git.x86_64 ,安装git

     图略

3、安装完毕后 ,去到相应的目录执行git clone xxxx.git ,提示warning: templates not found /usr/local/test-git/share/git-core/templates

解决思路

1、碰到问题先baidu+bing+google

    大概知道两种方案:一种指定安装路径重新安装一次git;第二方案,提示找不到templates,那就指定templates;采用第二方案,指定templates目录,资料(http://www.cnblogs.com/lucktian/p/6196877.html)显示需要指定templatedir这个变量,需要去到~/.gitconfig文件去设置

2、先获取已经安装git的templates目录

    执行rpm -ql git 查看安装路径

3、准备修改~/.gitconfig,添加templatedir的参数,结果发现没有~/.gitconfig文件,但是可以通过git config --global init.templatedir “/usr/share/git-core/templates”

    执行git config --global init.templatedir=/usr/share/git-core/templates 后发现竟然生成了.gitconfig文件,查看该文件

4、再执行git clone xxx.git 发现没有报错,可以正常拉取代码

思考

1、可能是因为之前安装了不同版本的git,没有卸载干净导致这个问题的;

2、查询的资料少的时候,结合已知信息多尝试;

3、config的设置是根据git config --global user.name "jwen" 联想过来的;