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
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的理解)的更多相关文章
- 【原创】关于Git暂存区的理解
关于Git暂存区的理解 暂存区可以说是Git的三大重要的区域之一,另外两个分别是工作目录和Git仓库,所以说对暂存区的深入理解可以帮助我们理解很多Git命令背后隐藏的工作原理.今天,本文将以 ...
- 关于git使用的几点理解
1.git为分布式的版本控制系统,有远程仓库和本地仓库,远程仓库和本地仓库之间建立关联关系后,可将本地仓库的更新push(相当于是内容同步)到远程仓库进行保存,远程仓库的作用相当于一个最终代码备份的地 ...
- 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 : ...
- 转 关于C#中派生类调用基类构造函数的理解
关于C#中派生类调用基类构造函数的理解 .c#class 本文中的默认构造函数是指在没有编写构造函数的情况下系统默认的无参构造函数 1. 当基类中没有自己编写构造函数时,派生类默认的调用 ...
- 【Git 学习三】深入理解git reset 命令
重置命令(git reset)是Git 最常用的命令之一,也是最危险最容易误用的命令.来看看git reset命令用法. --------------------------------------- ...
- Git 合并多次 commit 、 删除某次 commit
Git 合并多次 commit 有时候在一个分支的多次意义相近的 commit,会把整个提交历史搞得很混乱,此时可以将一部分的 commit 合并为一个 commit,以美化整个 commit 历史, ...
- [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 ...
- 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 ...
- [Git] git revert ( revert commit 和 revert merge)
转载自:http://blog.csdn.net/qinjienj/article/details/7621887 我们难免会因为种种原因执行一些错误的commit / push,git提供了reve ...
- git取消本地commit
如果不小心commit了一个不需要commit的文件,可以对其进行撤销. 先使用git log 查看 commit日志 commit 422bc088a7d6c5429f1d0760d008d86c5 ...
随机推荐
- BestCoder Round #66 1001
GTW likes math Accepts: 472 Submissions: 2140 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- PHP服务器文件管理器开发小结(九):jQuery动态表单实现文件下载
前文讨论的文件操作,无论是新建.编辑.移动.删除,都是服务端对本地文件系统的操作.这一节需要讨论一个涉及服务端和客户端协调进行的操作:文件下载. 简单的文件下载可以通过将相对路径写入超链接的方式进行, ...
- 在MD中使用Emoji
mark语法中支持emoji表情 具体语法是:emoji: 比如我输入 :smile: 就会出现微笑
- ORA-12012 ORA-20001 on ORACLE 12C (2420581.1)
Oracle数据库 - 企业版 - 12.2.0.1及更高版本本文档中的信息适用于任何平台. Doc ID 2420581.1 症状 在容器数据库中,警报日志中会显示以下错误: ORA-12012 ...
- Spark各个组件的概念,Driver进程
spark应用涉及的一些基本概念: 1.mater:主要是控制.管理和监督整个spark集群 2.client:客户端,将用应用程序提交,记录着要业务运行逻辑和master通讯. 3.sparkCon ...
- 那些经历过的Bug Unity的Invoke方法
有一个游戏对象,上面挂着 3 个脚本,如下: using System.Collections; using System.Collections.Generic; using UnityEngine ...
- OpenStack Weekly Rank 2015.07.27
Module Reviews Drafted Blueprints Completed Blueprints Filed Bugs Resolved Bugs Cinder 7 1 1 7 10 Sw ...
- LeetCode 110.平衡二叉树(C++)
给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1. 示例 1: 给定二叉树 [3,9,20,null,nu ...
- OpenCV细化算法简单解析
细化算法它的原理也很简单: 我们对一副二值图像进行骨架提取,就是删除不需要的轮廓点,只保留其骨架点.假设一个像素点,我们定义该点为p1,则它的八邻域点p2->p9位置如下图所示,该算法考虑p1点 ...
- c#-day03学习笔记
循环语句 一共有三种 1: For循环 2: while 循环 3: do while 循环 //1 //2 //4 For循环 语法 f ...