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 ...
随机推荐
- 8.9zju集训日记
和新队员的第一次比赛,前期开题方向基本正确,签到的速度比较快,中期读了旋转卡壳,矩阵和km的三道题目,都有一定的想法,但三个人意见不同没有往一个方向想,但其实旋转卡壳和km的题目思路几乎都对了,但是旋 ...
- 2015苏州大学ACM-ICPC集训队选拔赛(2)1004
草爷要的数 Problem Description 今天校队队员们准备放松一下,我们队就准备选一些数字玩,然而每个人喜欢的数字是不同的,刻盘喜欢x(1<=x<=1^9),凯凯喜欢y(1&l ...
- 两个数据库通过DataTable实现差异传输
两个主要方法 /// <summary>/// 用途:/// 用源表和目标表比较,返回差异的数据(目标表为参照物)/// /// 逻辑:/// 1.合并两个表/// 2.循环合并后得到的表 ...
- Oozie的缺点
Oozie使用的时候有以下不便: [a]Oozie调度的Workflow只能使用XML文件配置 [b]启动调度只能通过命令行 [c]无法通过Oozie界面调试调度脚本 [d]Oozie无法可视化调试脚 ...
- Why Nexiq 125032 USB Link Truck diagnostic tool is so helpful ?
As for as I am concerned , Heavy Duty Diagnostic Nexiq 125032 USB is a helpful tool , which has exce ...
- Linux关于用户信息的一些命令
1.用户增加删除[root@VM_0_13_centos ~]# useradd better407 #添加 better407 用户 [root@VM_0_13_centos ~]# passwd ...
- 数据结构---Java---HashMap
1.概述 [hash冲突]: 对某个元素进行哈希函数运算,得到一个地址值,要进行插入时,发现此地址被占用,称为hash冲突(哈希碰撞): [hash冲突解决]: 开放定址(发生冲突,继续寻找下一块未被 ...
- Python + Selenium 基础篇 - 打开和关闭浏览器
1.首先要下载浏览器对应的driver,并放到你的python安装目录 Chrome浏览器(chromedriver): http://npm.taobao.org/mirrors/chromedri ...
- 本地git的使用
git和svn的解析 git 教程 git rebase的用法 attion: one: git中是严格区分大小写的,文件名字大小写敏感 two: git中分为:工作区,暂存区,分支 three: ...
- 性能测试工具LoadRunner28-LR之内部数据参数类型
Date/Time 在“Parameter type”中您可以选择Date/Time,即:用当前的日期/时间替换参数.要指定日期/时间的格式,可以从格式列表中选择一个格式,或者指定您自己的格式. [l ...