创建版本库(操作都是在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 [iyunv@centos-linux git_home]# git add readme.txt
2 [iyunv@centos-linux git_home]# git commit -m "wrote a readme file"
3 [master (root-commit) 8a044aa] wrote a readme file13 1 file changed, 2 insertions(+)
14 create mode 100644 readme.txt
15 [iyunv@centos-linux git_home]#
第一步执行git add成功后是没有任何提示的
第二步git commit命令中 -m 后面输入的是本次提交的说明,一般输入的对当前提交记录的一个简单说明,这样在历史记录里查看的时候,就可以看到这个说明,从而知道每次提交的意义
并且这里需要知道git commit可以一次提交多个文件,也就是说你可以add 多次,但是只需要一次commit
1 [iyunv@centos-linux git_home]# touch file1.txt file2.txt file3.txt
2 [iyunv@centos-linux git_home]# ls
3 file1.txt file2.txt file3.txt readme.txt
4 [iyunv@centos-linux git_home]# git add file1.txt
5 [iyunv@centos-linux git_home]# git add file2.txt file3.txt
6 [iyunv@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 [iyunv@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 [iyunv@centos-linux git_home]#
总结
上面一共有学了三个命令
初始化一个git仓库:git init
添加文件到git仓库:
1. git add 文件名
2. git commit -m "说明"
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com