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


    创建版本库(操作都是在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 file13 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 "说明"

  • 相关阅读:
    Intent 传递Map数据
    android 读取.properties文件
    android 复制到剪切板
    SVN Update Error: Please execute the 'Cleanup' command
    Win8安装程序出现2502、2503错误解决方法
    启动系统自带的应用程序
    解决底部Button遮挡ListView最后一项内容的bug
    Intent传递list集合时异常解决
    Tomcate 启动异常,java.net.BindException: Address already in use: JVM_Bind:80的解决办法
    【Web】阿里icon图标gulp插件(gulp-qc-iconfont)
  • 原文地址:https://www.cnblogs.com/zhaof/p/6896723.html
Copyright © 2020-2023  润新知