当前位置: 首页 > news >正文

Git基本操作(add,commit的理解)

1.创建仓库

  ——创建工作目录(Working Directory)git三种副本:工作目录(Working Direcotry),暂存区域(Stage,索引(Index)),仓库(History)

#/home/yang/Documents/repo01
. ├── datafiles │   └── data.txt ├── test01 ├── test02 └── test03
# Initialize the local Git repository(在根目录下生成.git文件夹)
git init

2.查看文件状态

yang@mint-linux ~/Documents/repo01 $ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    datafiles/
#    test01
#    test02
#    test03
nothing added to commit but untracked files present (use "git add" to track)

 

3.添加文件

  ——git add files 把当前文件放入暂存区域

yang@mint-linux ~/Documents/repo01 $ git add .
yang@mint-linux ~/Documents/repo01 $ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
#    new file: datafiles/data.txt
#    new file: test01
#    new file: test02
#    new file: test03
#

3.提交文件

  ——git commit 给暂存区域生成快照并提交。

yang@mint-linux ~/Documents/repo01 $ git commit -m "Initial commit"
[master (root-commit) 3f79459] Initial commit
 4 files changed, 4 insertions(+)
 create mode 100644 datafiles/data.txt
 create mode 100644 test01
 create mode 100644 test02
 create mode 100644 test03
yang@mint-linux ~/Documents/repo01 $ git status
# On branch master
nothing to commit, working directory clean

4.查看文件内容变更

yang@mint-linux ~/Documents/repo01 $ echo "This is a change" > test01
yang@mint-linux ~/Documents/repo01 $ echo "and this is another change" > test02
yang@mint-linux ~/Documents/repo01 $ git diff
diff --git a/test01 b/test01
index 749eb2d..d0a432b 100644
--- a/test01
+++ b/test01
@@ -1,4 +1 @@
-datafiles
-test01
-test02
-test03
+This is a change
diff --git a/test02 b/test02
index e69de29..552c22e 100644
--- a/test02
+++ b/test02
@@ -0,0 +1 @@
+and this is another change
yang@mint-linux ~/Documents/repo01 $ git commit -a -m "These are new changes"

5.查看工作目录提交记录

(回顾:git status--查看文件状态,git-diff--查看文件内容状态)

# Make some changes in the file
echo "This is a new change" > test01
echo "and this is another new change" > test02
yang@mint-linux ~/Documents/repo01 $ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#    modified:   test01
#    modified:   test02
#
no changes added to commit (use "git add" and/or "git commit -a")
yang@mint-linux ~/Documents/repo01 $ git diff
diff --git a/test01 b/test01
index d0a432b..18fec42 100644
--- a/test01
+++ b/test01
@@ -1 +1 @@
-This is a change
+This is a new change
diff --git a/test02 b/test02
index 552c22e..0b17386 100644
--- a/test02
+++ b/test02
@@ -1 +1 @@
-and this is another change
+and this is another new change
yang@mint-linux ~/Documents/repo01 $ git add . && git commit -m "More changes - type in the commit message"
[master 8a18ab1] More changes - type in the commit message
 2 files changed, 2 insertions(+), 2 deletions(-)
yang@mint-linux ~/Documents/repo01 $ git log
commit 8a18ab1c77ecaf049d17e5ac8fb682ae618cd710
Author: Will Hunting <yangqionggo@gmail.com>
Date:   Sun Aug 18 18:57:38 2013 +0800

    More changes - type in the commit message

commit a6bd74cdbaa1b349d537008f33fa186eae9d48c9
Author: Will Hunting <yangqionggo@gmail.com>
Date:   Sun Aug 18 18:56:07 2013 +0800

    These are new changes

commit 3f794593e7008286a893a5d00f81ee5757140469
Author: Will Hunting <yangqionggo@gmail.com>
Date:   Sun Aug 18 18:50:58 2013 +0800

    Initial commit

6.删除文件

如果你删除了一个在版本控制之下的文件,那么使用git add .不会在索引中删除这个文件。需要通过带-a选项的git commit命令和-A选项的git add命令来完成

# Create a file and put it under version control
touch nonsense.txt
git add . && git commit -m "a new file has been created"
# Remove the file
rm nonsense.txt
# Try standard way of committing -> will not work 
git add . && git commit -m "a new file has been created"
# Now commit with the -a flag
git commit -a -m "File nonsense.txt is now removed"
# Alternatively you could add deleted files to the staging index via
git add -A . 
git commit -m "File nonsense.txt is now removed"

7.更正提交的信息

git commit --amend -m "More changes - now correct"

转载于:https://www.cnblogs.com/yangqionggo/p/3266293.html

相关文章:

  • 怎么编写测试驱动程序
  • 百度地图 - 合并模拟器和真机的静态库文件
  • vb常用命名空间
  • Java解析xml配置文件合成器
  • HTTP 状态代码及其定义
  • VS2008快捷键大全
  • 新浪微博API
  • STM32菜鸟成长记录---RS485通讯协议的应用
  • 可滚动和可更新的结果集
  • c++ builder TreeView控件节点遍历
  • 最近看的几部动漫
  • DataGrid的实现超链接的方法小结
  • cocos2d-x学习笔记------动画人物跑起来吧!
  • bump mapping -- per-fragment lighting computation (Phong shading)
  • 第二课 寄存器
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • CentOS6 编译安装 redis-3.2.3
  • extjs4学习之配置
  • Fundebug计费标准解释:事件数是如何定义的?
  • Hexo+码云+git快速搭建免费的静态Blog
  • Java读取Properties文件的六种方法
  • Java多线程(4):使用线程池执行定时任务
  • JS创建对象模式及其对象原型链探究(一):Object模式
  • JS进阶 - JS 、JS-Web-API与DOM、BOM
  • Just for fun——迅速写完快速排序
  • NSTimer学习笔记
  • PyCharm搭建GO开发环境(GO语言学习第1课)
  • Spark VS Hadoop:两大大数据分析系统深度解读
  • Transformer-XL: Unleashing the Potential of Attention Models
  • Vue UI框架库开发介绍
  • 基于 Babel 的 npm 包最小化设置
  • 使用 Docker 部署 Spring Boot项目
  • 数组大概知多少
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • 最近的计划
  • k8s使用glusterfs实现动态持久化存储
  • #git 撤消对文件的更改
  • (13):Silverlight 2 数据与通信之WebRequest
  • (pytorch进阶之路)扩散概率模型
  • (仿QQ聊天消息列表加载)wp7 listbox 列表项逐一加载的一种实现方式,以及加入渐显动画...
  • (附源码)计算机毕业设计ssm基于Internet快递柜管理系统
  • (附源码)计算机毕业设计高校学生选课系统
  • (实战篇)如何缓存数据
  • (幽默漫画)有个程序员老公,是怎样的体验?
  • (转)http协议
  • .gitattributes 文件
  • .NET CLR Hosting 简介
  • .net core 源码_ASP.NET Core之Identity源码学习
  • .net Stream篇(六)
  • .net2005怎么读string形的xml,不是xml文件。
  • .NET企业级应用架构设计系列之技术选型
  • /usr/local/nginx/logs/nginx.pid failed (2: No such file or directory)
  • @FeignClient 调用另一个服务的test环境,实际上却调用了另一个环境testone的接口,这其中牵扯到k8s容器外容器内的问题,注册到eureka上的是容器外的旧版本...
  • @param注解什么意思_9000字,通俗易懂的讲解下Java注解
  • @RequestBody详解:用于获取请求体中的Json格式参数