解决git创建版本库时报错 unable to auto-detect email address 与 fatal: This operation must be run in a work tree

昨天学习利用git配置版本库时,配置好的git,要commit一些修改,就遇到了这个问题。

首先新建了一个名为learngit的空版本库,然后在learngit目录下新建了一个readme.txt文件,内容如下:

Git is a version control system.
Git is free software.

此处的readme.txt放到learngit目录下(子目录也行),因为这是一个Git仓库,放到其他地方Git找不到这个文件。

然后执行以下两步:

第一步:使用命令 git add readme.txt添加到暂存区里面去。

第二步:用命令 git commit告诉Git,把文件提交到仓库。本人输入的是:  

git commit -m "wrote a readme file"

执行完第二步操作后,问题来了。先后出现了以下两个报错:

1)unable to auto-detect email addres

具体报错内容如下:

** Please tell me who you are.
Run
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"


to set your account's default identity.
Omit --global to set the identity only in this repository.


fatal: unable to auto-detect email address (got 'tim@newton.(none)')


解决方案如下:
找到工程目录的.git文件夹,打开之后找到config文件,在最后边加上一句话
[user]
 email=your email
 name=your name
your email 和your name随便写上就行
 

2)fatal: This operation must be run in a work tree

解决了第一个报错以后,继续执行  git commit -m "wrote a readme file"

结果,又提示报错:

fatal: this operation must be run in a work tree

参考网上reference2给出的方法可解决该问题,再次感谢。(ps:我之前忘记激活git库了,后来重试了一遍不再出现问题2)

若读者解决问题一后遇到该问题,可考虑以下解决方案:

由于git init –bare 方法创建一个裸仓库,在该仓库无法进行任何git操作,所以抛出错误.
解决方法:在该仓库目录下,新建文件夹,进入该文件夹,执行如下命令:
1. touch Readme
2. git init
3. git add Readme
4. git commit -m 'initial commit' Readme

 

本博客参考了以下链接:
References:
[1] https://blog.csdn.net/liufangbaishi2014/article/details/50037507 

[2] https://blog.csdn.net/weixin_35755389/article/details/52679693

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值