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
files changed, insertions(+)
create mode datafiles/data.txt
create mode test01
create mode test02
create mode 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
--- a/test01
+++ b/test01
@@ -, + @@
-datafiles
-test01
-test02
-test03
+This is a change
diff --git a/test02 b/test02
index e69de29..552c22e
--- a/test02
+++ b/test02
@@ -, + @@
+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
--- a/test01
+++ b/test01
@@ - + @@
-This is a change
+This is a new change
diff --git a/test02 b/test02
index 552c22e..0b17386
--- a/test02
+++ b/test02
@@ - + @@
-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
files changed, insertions(+), deletions(-)
yang@mint-linux ~/Documents/repo01 $ git log
commit 8a18ab1c77ecaf049d17e5ac8fb682ae618cd710
Author: Will Hunting <yangqionggo@gmail.com>
Date: Sun Aug :: + More changes - type in the commit message commit a6bd74cdbaa1b349d537008f33fa186eae9d48c9
Author: Will Hunting <yangqionggo@gmail.com>
Date: Sun Aug :: + These are new changes commit 3f794593e7008286a893a5d00f81ee5757140469
Author: Will Hunting <yangqionggo@gmail.com>
Date: Sun Aug :: + 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"

Git基本操作(add,commit的理解)的更多相关文章

  1. 【原创】关于Git暂存区的理解

    关于Git暂存区的理解      暂存区可以说是Git的三大重要的区域之一,另外两个分别是工作目录和Git仓库,所以说对暂存区的深入理解可以帮助我们理解很多Git命令背后隐藏的工作原理.今天,本文将以 ...

  2. 关于git使用的几点理解

    1.git为分布式的版本控制系统,有远程仓库和本地仓库,远程仓库和本地仓库之间建立关联关系后,可将本地仓库的更新push(相当于是内容同步)到远程仓库进行保存,远程仓库的作用相当于一个最终代码备份的地 ...

  3. Git error on commit after merge - fatal: cannot do a partial commit during a merge

    Git error on commit after merge - fatal: cannot do a partial commit during a merge this answer is : ...

  4. 转 关于C#中派生类调用基类构造函数的理解

    关于C#中派生类调用基类构造函数的理解 .c#class       本文中的默认构造函数是指在没有编写构造函数的情况下系统默认的无参构造函数 1.  当基类中没有自己编写构造函数时,派生类默认的调用 ...

  5. 【Git 学习三】深入理解git reset 命令

    重置命令(git reset)是Git 最常用的命令之一,也是最危险最容易误用的命令.来看看git reset命令用法. --------------------------------------- ...

  6. Git 合并多次 commit 、 删除某次 commit

    Git 合并多次 commit 有时候在一个分支的多次意义相近的 commit,会把整个提交历史搞得很混乱,此时可以将一部分的 commit 合并为一个 commit,以美化整个 commit 历史, ...

  7. [Git/GitHub] Tutorial 1. Git download and commit first project

    1. Install at https://git-scm.com/downloads 2. Set up your name and email $ git config --global user ...

  8. Git冲突:commit your changes or stash them before you can merge.

    用git pull来更新代码的时候,遇到了下面的问题: error: Your local changes to the following files would be overwritten by ...

  9. [Git] git revert ( revert commit 和 revert merge)

    转载自:http://blog.csdn.net/qinjienj/article/details/7621887 我们难免会因为种种原因执行一些错误的commit / push,git提供了reve ...

  10. git取消本地commit

    如果不小心commit了一个不需要commit的文件,可以对其进行撤销. 先使用git log 查看 commit日志 commit 422bc088a7d6c5429f1d0760d008d86c5 ...

随机推荐

  1. P3970 [TJOI2014]上升子序列

    传送门 DP 十分显然的DP,但是不好写 设 f[ i ] 表示以第 i 个数作结尾时的方案数,原序列为 a 如果不考虑相同的序列: 那么转移就是 Σ f[ j ] (0< j < i & ...

  2. UVA1714 Keyboarding

    传送门 坑很多的一题 这里要感谢crk大佬提前帮我把所有的坑都踩了一遍...233 讲一下题目的意思: 给你一个神奇的 r*c 的键盘 (r,c<=50) 上面有大写的字母,数字,' - '号 ...

  3. 江西财经大学第一届程序设计竞赛 C

    链接:https://www.nowcoder.com/acm/contest/115/C来源:牛客网 题目描述 决赛圈还剩下两个人,“伏地魔”XDD和跑毒进圈的FZL,XDD拿着狙击枪AWM瞄准并准 ...

  4. ADO执行事务

    在工作中遇到,需要批量提交的.在sql2008以后有表变量定义,可以实现.但个人比较习惯用C#,就有下面代码,直接上代码... using (SqlConnection conn = new SqlC ...

  5. java thread start到run:C++源码分析

    转:https://hunterzhao.io/post/2018/06/11/hotspot-explore-inside-java-thread-run/ 整体流程 java new Thread ...

  6. Eclipse + Git + 码云

    1. 进入码云个人首页 点击自己的名称即可 2. 添加一个项目 3. 在Eclipse中创建一个本地Git Eclipse不建议git目录创建在项目的目录下,因此另选一个目录作为本地Git目录 选择一 ...

  7. PHP、thinkPHP5.0开发网站文件管理功能(三)重命名文件

    public function renames(){ if(request()->isAjax()){ $file = iconv('UTF-8','GB2312',urldecode(inpu ...

  8. 基于MVC模式开发的后台框架

    1.ThinkCMF 2.NFine快速开发平台 3.力软快速开发框架 如有好的开发框架希望可以一起交流

  9. python 运算符-赋值运算

    结果是值 算数运算: a = 10 * 10 赋值运算: a = a + 1  a  +=1  结果是布尔值 比较运算: a  = 1 > 5 逻辑运算: a =  1 > 6 or 1= ...

  10. [转]jquery的ajax交付时“加载中”提示的处理方法

    本文转自:http://www.educity.cn/wenda/77121.html jquery的ajax提交时“加载中”提示的处理方法    方法1:使用ajaxStart方法定义一个全局的“加 ...