码迷,mamicode.com
首页 > 其他好文 > 详细

git使用(二)----创建版本库

时间:2017-05-24 00:48:11      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:告诉   span   str   wro   email   log   仓库   run   dir   

创建版本库(操作都是在linux环境下)

什么是版本库呢?版本库又名仓库,英文名repository,其实就是一个目录,可以进行增删查改

创建一个目录,这里在根目录下创建一个git_home目录
mkdir /git_home
cd git_home
git init

技术分享

这样就创建好了一个仓库,当然目前是一个空仓库

这个时候在当前目录通过ls -a可以看到多了一个.git的目录

 

把文件添加到版本库

版本控制系统可以告诉你每次的改动,比如在第5行加了一个单词“Linux”,在第8行删了一个单词“Windows”。而图片、视频这些二进制文件,虽然也能由版本控制系统管理,但没法跟踪文件的变化,只能把二进制文件每次改动串起来,也就是只知道图片从100KB改成了120KB,但到底改了啥,版本控制系统不知道,也没法知道。

我们在git_home目录下创建一个文件,并填写如下内容
git is a version control system
git is fee software

把文件放到git需要两步:
1. git add 文件名
2. git commit -m "说明"

下面我们把readme.txt放到git,操作如下:

 1 [root@centos-linux git_home]# git add readme.txt
 2 [root@centos-linux git_home]# git commit -m "wrote a readme file"
 3 [master (root-commit) 8a044aa] wrote a readme file
 4 Committer: root <root@centos-linux.shared>
 5 Your name and email address were configured automatically based
 6 on your username and hostname. Please check that they are accurate.
 7 You can suppress this message by setting them explicitly. Run the
 8 following command and follow the instructions in your editor to edit
 9 your configuration file:
10 git config --global --edit
11 After doing this, you may fix the identity used for this commit with:
12 git commit --amend --reset-author
13 1 file changed, 2 insertions(+)
14 create mode 100644 readme.txt
15 [root@centos-linux git_home]#

第一步执行git add成功后是没有任何提示的
第二步git commit命令中 -m 后面输入的是本次提交的说明,一般输入的对当前提交记录的一个简单说明,这样在历史记录里查看的时候,就可以看到这个说明,从而知道每次提交的意义
并且这里需要知道git commit可以一次提交多个文件,也就是说你可以add 多次,但是只需要一次commit

 1     [root@centos-linux git_home]# touch file1.txt file2.txt file3.txt
 2     [root@centos-linux git_home]# ls
 3     file1.txt  file2.txt  file3.txt  readme.txt
 4     [root@centos-linux git_home]# git add file1.txt
 5     [root@centos-linux git_home]# git add file2.txt file3.txt
 6     [root@centos-linux git_home]# git status
 7     On branch master
 8     Changes to be committed:
 9       (use "git reset HEAD <file>..." to unstage)
10             new file:   file1.txt
11             new file:   file2.txt
12             new file:   file3.txt
13     [root@centos-linux git_home]# git commit -m "add 3 files"
14     [master 4d0b5e2] add 3 files
15      3 files changed, 0 insertions(+), 0 deletions(-)
16      create mode 100644 file1.txt
17      create mode 100644 file2.txt
18      create mode 100644 file3.txt
19     [root@centos-linux git_home]#

 

总结

 

上面一共有学了三个命令
初始化一个git仓库:git init
添加文件到git仓库:
1. git add 文件名
2. git commit -m "说明"

 

git使用(二)----创建版本库

标签:告诉   span   str   wro   email   log   仓库   run   dir   

原文地址:http://www.cnblogs.com/zhaof/p/6896723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!