zoukankan      html  css  js  c++  java
  • Git 单机版

    Git 是一个分布式的开源版本控制系统,也就是说,每台机器都可以充当控制中心,我从本机拉取代码,再提交代码到本机,不需要依赖网络,各自开发各自的

    如何创建 git 仓库:

    [root@localhost ~]$ yum install -y git    # 安装git
    [root@localhost ~]$ mkdir -p /data/git    # 创建要作为git仓库的目录
    [root@localhost ~]$ cd /data/git          # 进入该目录
    [root@localhost git]$ git init            # 初始化仓库
    [root@localhost git]$ git config --global user.name "Your Name"         # 配置用户,以便知道提交代码的人是谁
    [root@localhost git]$ git config --global user.email you@example.com    # 配置邮箱,以便联系到提交代码的人

    如何提交代码到 git 仓库:

    [root@localhost git]$ touch 1.txt      # 创建一个测试文件
    [root@localhost git]$ git add 1.txt    # 添加到版本控制中心
    [root@localhost git]$ git commit -m 'add new file 1.txt' 1.txt    # 提交到git仓库
    [root@localhost git]$ git status       # 查看当前仓库中的状态

    修改代码后如何提交到 git 仓库:

    [root@localhost git]$ echo "abc" >> 1.txt    # 修改文件内容
    [root@localhost git]$ git diff 1.txt         # 还没提交到代码仓库之前,可以对比当前文件跟代码仓库的文件有什么不同
    [root@localhost git]$ git commit -m 'add some character to 1.txt' 1.txt     # 提交到代码仓库
    [root@localhost git]$ git status    # 查看当前仓库中的状态

    如何回滚版本:

    [root@localhost git]$ git log --pretty=oneline           # 查看提交过的版本日志
    [root@localhost git]$ git reset --hard 0e6ff268923a54    # 回滚到指定的版本
    [root@localhost git]$ git reflog                         # git reflog 可以查看所有分支的所有操作记录

    如何撤销修改:

    [root@localhost git]$ rm -f 1.txt    # 如果我不小心删除了文件,如何恢复回来
    [root@localhost git]$ git checkout -- 1.txt    # 重新检出文件即可
    [root@localhost git]$ echo "aaa" >> 1.txt    # 如果我修改了文件
    [root@localhost git]$ git add 1.txt          # 添加到版本控制中心,但这时我不想提交了,想恢复修改前的文件,该如何恢复
    [root@localhost git]$ git reset HEAD 1.txt   # 先重置HEAD(HEAD可以理解为一个游标,一直指向当前我们所在版本库的地址,就是我们当前所在版本库的头指针)
    [root@localhost git]$ git checkout -- 1.txt  # 再重新检出文件即可

    如何删除文件:

    # 如果我们直接使用 rm -f 1.txt 只是删除了本地文件,版本库里的文件还是没有删除的,因此要用下面的方法
    [root@localhost git]$ git rm 1.txt # 删除本地文件 [root@localhost git]$ git commit -m 'delete file 1.txt' # 提交到版本库,会自动把版本库里的文件也删除

        

  • 相关阅读:
    Oracle:PL/SQL--流程控制——作业练习:向表中循环插入ID编号
    Oracle:PL/SQL--流程控制(三)——循环结构:loop、while-loop、for-loop
    Oracle:PL/SQL--流程控制(三)——循环结构:loop、while-loop、for-loop
    Oracle:PL/SQL--打开控制台or关闭控制台
    Win10远程桌面及防火墙配置
    H3C-Telnet
    网络工程师(软考)心得
    《网络工程师 考前冲刺100题》思维导图
    《2019上半年网络工程师考试大纲》
    网络设计:搭建校园网(组网工程课设)【译】
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10291237.html
Copyright © 2011-2022 走看看