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' # 提交到版本库,会自动把版本库里的文件也删除

Git 单机版的更多相关文章

  1. Git 联机版

    简介: 之前研究了 Git 单机版 ( 单兵作战 ),今天来研究一下 Git 联机版 ( 团队协作 )! GitHub 是一个开源的代码托管平台,可以分享自己的代码到该平台上,让大家参与开发或供大家使 ...

  2. Twitter Storm安装配置(Ubuntu系统)单机版

    要使用storm首先要安装以下工具:JDK.Python.zookeeper.zeromq.jzmq.storm (注:各个模块都是独立的,如果安装失败或者卡顿可以单独百度某个模块的安装,都是可以的. ...

  3. 结对编程—黄金点游戏WinForm单机版

    本小游戏场景来自邹欣老师的<移山之道>一书: "阿超的课都是下午两点钟,这时班上不少的同学都昏昏欲睡,为了让大家兴奋起来,阿超让同学玩一个叫"黄金点"的游戏: ...

  4. JAVA课程设计——单机版五子棋

    JAVA课程设计--单机版五子棋 1.团队名称.团队成员介绍 团队名称:Gomoku小分队 团队成员: 网络1512 201521123038 游舒婷(组长) 网络1512 201521123043 ...

  5. python爬虫之git的安装

      一.初始 1.发展历史 *最开始没有对代码的管理,导致很多东西混乱和丢失. *后来大家想了一个办法,用最简单最笨的方法,各种复制文件夹. *然后就出现了版本控制的工具. 1.单机版:RCS(198 ...

  6. docker安装fastdfs单机版

    docker search fastdfs INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/season/fas ...

  7. Windows Git 服务器 客户端 Delphi Git配置

    装Git后本地单机版就有了版本管理功能. git 使用记录 git 客户端 这2个工具足够用. git for windows,http://git-scm.com/download/,Git-1.9 ...

  8. linux上如何安装git

    安装依赖软件 yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc yum instal ...

  9. 单机版搭建kubernetes(K8s)

    准备 云原生的概念越来越火,忍不住去看了看kubernetes,初次接触,晕晕乎乎的,于是不管三七二十一,先搭建个单机版的再说(没钱买服务器,目前也懒得装虚拟机),跑起来也算是第一步吧.网上教程一顿搜 ...

随机推荐

  1. Change Data template dynamically

    1. Attached Property bound to task state. Any change will dynamically set data template.2. Visual St ...

  2. Windows 7 incorrectly reports "No Internet Access"

    PROBLEM DESCRIPTION Windows 7 may sometimes report that it has "No Internet Access"; this ...

  3. Python之生成二面体群元素

    from sympy.combinatorics.named_groups import DihedralGroup from collections import Counter n = 12 G ...

  4. Policy Gradient

    Policy Gradient是区别于Q-Learning为代表的value based的方法.policy gradient又可以叫reinforce算法(Williams, 1992). 如今的A ...

  5. 你对linux了解多少,Linux 系统结构详解!

    最近一直有人在请教老K关于Linux系统相关问题,这里我就该问题做个详解,Linux系统一般有4个主要部分:内核.shell.文件系统和应用程序. 内核.shell和文件系统一起形成了基本的操作系统结 ...

  6. (笔记)Mysql命令create table:创建数据表

    create table命令用来创建数据表. create table命令格式:create table <表名> (<字段名1> <类型1> [,..<字段 ...

  7. gcc -lpthread

    转自:http://www.cnblogs.com/suntp/p/6473751.html 如果用gcc编译使用了POSIX thread的程序时,通常需要加额外的选项,以便使用thread-saf ...

  8. SpringMVC系列(七)视图解析器和视图

    在springmvc.xml里面配置视图解析器 <!-- 配置视图解析器: 如何把 handler 方法返回值解析为实际的物理视图 --> <bean class="org ...

  9. e777. 获得JList组件的所有项

    // Create a list String[] items = {"A", "B", "C", "D"}; JLis ...

  10. Unity -----一些可能存在的错误

    关于Unity中的资源管理,你可能遇到这些问题 张鑫 8 个月前 原文链接:关于Unity中的资源管理,你可能遇到这些问题 - Blog 在优化Unity项目时,对资源的管理可谓是个系统纷繁的大工程. ...