3:git文件添加到版本库
文件添加到版本库
1:创建文件
vi test.txt
2:编辑文件
点击i,进入vi编辑模式
输入"我今天吃了一个苹果";
按ESC,输入":wq"
文件test.txt即被创建
3:查看文件内容
cat text.txt
我今天吃了一个苹果
4:查看文件状态:
git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be commited)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
5:把文件提交到暂存区
git add test.txt
6:查看文件状态信息
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
因为是新建的文件,所以会有git rm --cached的提示
7:把文件提交到版本库
$ git commit -m "第一次提交"
[master (root-commit) b3d952f] 第一次提交
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+)
create mode 100644 test.txt
8:查看文件状态信息
$ git status
On branch master
nothing to commit, working directory clean
当前工作区已经没有要提交的东西了,可以继续编辑了。
9:查看刚提交的信息
$ git log
commit b3d952f7914444238f70410a97f15f50200e63af
Author: zhangyanbing <zhangyanbing@benmu-health.com>
Date: Thu May 5 15:07:28 2016 +0800
第一次提交
$ git log --pretty=oneline
b3d952f7914444238f70410a97f15f50200e63af 第一次提交
10:继续编辑
vi test.txt
输入:第二天,我吃了一个梨
11:查看内容:
$ cat test.txt
我今天吃了一个苹果
第二天,我吃了一个梨
12:查看修改内容
$ git diff test.txt
diff --git a/test.txt b/test.txt
index e526e5e..c6e02ad 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,2 @@
我今天吃了一个苹果
+第二天,我吃了一个梨
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
13:查看文件状态信息
$ git status
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test.txt
由于是vi编辑,保存后默认添加到暂存区
14:commit到版本库
$ git commit -m "我今天吃了一个梨"
[master warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
6cc4f1c] 我今天吃了一个梨
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+)
15:使用webstorm文本编辑器编辑
输入:第三天,我吃了一个香蕉
16:查看内容
$ cat test.txt
我今天吃了一个苹果
第二天,我吃了一个梨
第三天,我吃了一个香蕉
17:查看修改内容
$ git diff test.txt
diff --git a/test.txt b/test.txt
index c6e02ad..3306a19 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
我今天吃了一个苹果
第二天,我吃了一个梨
+第三天,我吃了一个香蕉
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
18:查看文件状态信息
$ 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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
由于使用普通文本编辑器,修改内容还在工作区,没有添加到暂存区
19:保存文件到暂存区:
git add test.txt
20:保存文件到版本库
$ git commit -m "我今天吃了一个香蕉"
[master warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
9f65338] 我今天吃了一个香蕉
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+)