git创建版本库

发布时间 2023-04-13 22:56:05作者: 是对的人

之前都是按照人家提供好的参考文档一步步使用git,发现基本没有报错,即使有报错,也能在文档中找到解决办法。但是,最近自己新装了个centos系统,想创建一个新的git版本库,发现居然出现了之前从来没有碰到过的问题。所以呢,在这篇文章中记录一下初始环境下git创建版本库的过程。

 

1.使用 git init 命令来初始化一个 Git 仓库,Git 的很多命令都需要在 Git 的仓库中运行,所以 git init 是使用 Git 的第一个命令:

git init

在当前目录下执行上诉命令,该命令执行完后会在当前目录生成一个 .git 目录,该目录包含了资源的所有元数据,其他的项目目录保持不变。

当然也可以直接指定目录作为Git仓库:

git init socket

初始化后,会在 newrepo 目录下会出现一个名为 .git 的目录,所有 Git 需要的数据和资源都存放在这个目录中。

2.将文件纳入版本控制,需要先用 git add 命令告诉 Git 开始对这些文件进行跟踪,然后提交:

git add README     # 添加指定文件
git add .          # 添加所有文件
git commit -m '初始化项目版本'

正好碰到这次的主要问题:

*** 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 'root@citta.(none)')

不知道我是谁?使用命令git config --list查看下git配置:

git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

原来是没有配置git。所以,需要配置一些信息告诉git我们的身份,可以执行下面的命令来配置:

git config user.name citta
git config user.email citta@gmail.com

然后,再去执行git commit命令就可以成功了。