status
- 接着之前初始化的仓库,我们在MyProject目录下右键打开Git bash,运行
git status
命令看看会出现什么东西。
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git status
On branch master
nothing to commit, working tree clean
- 我们往
README.md
里面添加一些内容,再运行git status
命令查看结果
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md #注意这里是红色的
no changes added to commit (use "git add" and/or "git commit -a")
1.png
git status
命令可以输出仓库当前的状态,上面的命令输出告诉我们,README.md已经被修改过了,但还没有对修改进行提交。
接下来,我们使用git diff
命令查看具体修改了什么内容。
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git diff
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory
diff --git a/README.md b/README.md
index 106287c..f83e8a5 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,2 @@
Hello Git!
+Git is free software. #注意这是绿色的,也就是新增的内容。
2.png
- 通过
git status
命令我们知道了哪些文件进行了修改,并且git diff
还可以告诉我们具体修改了哪些内容。这样我们就可以安心的把它们提交到仓库了。
第一步,先用git add
命令,命令行没有输出什么提示,我们再用git status
命令看看发现‘modified: README.md’已经从红色变为绿色了。
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git add README.md
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md # 注意这是绿色的
第二步,使用git commit
进行提交。
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git commit -m "add distributed"
[master 668e5ad] add distributed
1 file changed, 1 insertion(+)
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git status
On branch master
nothing to commit, working tree clean
3.png
小结
- 初始化一个 Git 仓库,使用 git init 命令。
- 添加文件到 Git 仓库,分两步: 使用命令
git add <file>
,可反复多次使用,添加多个文件; 使用命令git commit -m <message>
完成提交。
LS
案例
- 我们创建几个文件在工作目录里面,使用
git status
命令输出仓库当前的状态
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ touch index.php login.php
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git status
On branch mastergit
Untracked files: #未被追踪的文件
(use "git add <file>..." to include in what will be committed)
index.php
login.php
no changes added to commit (use "git add" and/or "git commit -a")
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$
4.png
- 下面,我们对
index.php
文件的修改追踪,再通过git status
命令查看当前仓库状态
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git add index.php
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.php #注意这是绿色的
Untracked files:
(use "git add <file>..." to include in what will be committed)
login.php #注意这是红色的
- 我们把login.php也一并提交到仓库
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git add login.php
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git commit -m "add tow files"
[master ea56a43] add tow files
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 index.php
create mode 100644 login.php
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
$ git status
On branch master
nothing to commit, working tree clean
23696@DESKTOP-GKRBCVI MINGW64 ~/Desktop/MyProject (master)
5.png
这个案例非常简单,一个是为了再次熟悉流程,另外就是告诉大家可以多次在add后,一次commit完成提交。
网友评论