一.git安装
在Ubuntu 14.04中安装:
1.检查是否安装了git:
在终端输入git
2.如果提示没有安装,则输入
sudo apt-get install git
二.创建版本仓
第一步,创建一个空目录:
$ mkdir learngit
$ cd learngit
$ pwd
/home/xiaobao/learngit
第二步,通过git init
命令把这个目录变成Git可以管理的仓库:
$ git init
初始化空的 Git 仓库于 /home/xiaobao/learngit/.git/
一个空的仓库(empty Git repository)就创建好了,你的learngit目录下多了一个.git
的目录,(但是我的电脑里没有出现.git目录, 那是因为这个目录默认是隐藏的,用ls -ah
命令就可以看见。)。
这个目录是Git来跟踪管理版本库的,没事千万不要手动修改这个目录里面的文件,不然改乱了,就把Git仓库给破坏了。
三.添加文件到版本仓
1.在终端中,在learngit目录下,输入:
$vi readme.txt
这是会打开一个文件名为readme.txt的编辑器,手动输入以下内容(按i输入内容,输入完成后保存):
2.添加文件到版本仓
用命令git add
告诉Git,把文件添加到仓库:
$ git add readme.txt
3.用命令git commit
告诉Git,把文件提交到仓库:
$ git commit -m "wrote a readme file"
[master (根提交) 71fed51] wrote a readme file
1 file changed, 2 insertions(+)
create mode 100644 readme.txt
我在这一步出现了问题:
xiaobao@xiaobao-Vostro-1014:~/learngit$ git commit -m "wrote a readme file"
*** 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 'xiaobao@xiaobao-Vostro-1014.(none)')
我的解决办法是:根据提示,在终端输入了两条命令
$ git config --global user.email "xiaobao@xiaobao-Vostro-1014.local
$ git config --global user.name "xiaobao"
然后在终端输入:$git commit -m "wrote a readme file"即出现正确的提示