🧊使用命令git status查看当前仓库内的文件和上一次commit操作后的文件差异,提示在主分支On branch master被修改过了,Changes not staged for commit:但还没有准备提交的修改文件modified: readme.txt,推荐你使用命令git add <file>去将这个文件添加到pool中以备后续commit,或者使用命令git restore <file>去忽略这部分改动。no changes added to commit没有新的通过add文件到pool中去用于commit。
1 2 3 4 5 6 7 8 9
$ 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.txt
no changes added to commit (use "git add" and/or "git commit -a")
比较查看
🧊使用命令git diff查看具体修改的内容,显示的格式是Unix通用的diff格式。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ git diff diff --git a/readme.txt b/readme.txt index 80a2774..19ac55a 100644 --- a/readme.txt +++ b/readme.txt @@ -1,2 +1,3 @@ Git test: -step1:文件自身的创建是和Git没有关系的,可以用windows的可视化操作创建,也可以用终端指令创建任意文件or目录。 \ No newline at end of file +step1:文件自身的创建是和Git,【这里删除了“没有关系的”】可以用windows的可视化操作创建,也可以用终端指令创建任意文件or目录。 +step2:🧊使用命令`git add`将任意一个文件添加到Git仓库,可以认为是暂时提交到Git 仓库中的一个池子pool中 \ No newline at end of file
$ git diff diff --git a/readme.txt b/readme.txt index 80a2774..7d21f15 100644 --- a/readme.txt +++ b/readme.txt @@ -1,2 +1,3 @@ Git test: -step1:文件自身的创建是和Git没有关系的,可以用windows的可视化操作创建,也可以用终端指令创建任意文件or目录。 \ No newline at end of file +step1:文件自身的创建是和Git没有关系的,可以用windows的可视化操作创建,也可以用终端指令创建任意文件or目录。 +step2:🧊使用命令`git add`将任意一个文件添加到Git仓库,可以认为是暂时提交到Git仓库中的一个池子pool中 \ No newline at end of file
修改添加
🧊使用命令git add将修改动的文件再次添加到pool。
🧊使用命令git status再次查看仓库中文件的状态信息,文件modified: readme.txt准备被提交Changes to be committed:。
1 2 3 4 5 6
$ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: readme.txt
$ 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.txt
Untracked files: (use "git add <file>..." to include in what will be committed) LICENSE
no changes added to commit (use "git add" and/or "git commit -a")
$ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: readme.txt
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.txt
$ 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.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git status On branch master nothing to commit, working tree clean
$ 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.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git status On branch master nothing to commit, working tree clean
$ git status On branch master nothing to commit, working tree clean
$ 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.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git restore readme.txt
$ git status On branch master nothing to commit, working tree clean
撤销添加
如果已经将文件修改添加到了暂存区,但是又想撤销这次添加,Git同样告诉我们,用命令git reset HEAD <file>可以把暂存区的修改撤销掉(unstage),重新放回工作区,但是这时候的工作区文件还是有修改:
$ git status On branch master nothing to commit, working tree clean
$ 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.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff diff --git a/readme.txt b/readme.txt index b865854..016f23f 100644 --- a/readme.txt +++ b/readme.txt @@ -3,4 +3,5 @@ step1:文件自身的创建是和Git没有关系的,可以用windows的可 step2:🧊使用命令`git add`将任意一个文件添加到Git仓库,可以认为是暂时提交到Git仓库中的一个池子pool中 step3:🧊使用命令`git commit`将前面add操作添加到池子pool中的文件提交到仓库,因此add只能添加一个文件,但是commit可以一次性将pool中的所有文件 提交。 step4:自定义修改文件内容,保存文件内容。 -step5:🧊使用命令`git status`查看当前仓库内的文件和上一次commit操作后的文件差异,提示在主分支`On branch master`被修改过了,`Changes not staged for commit:`但还没有准备提交的修改文件`modified: readme.txt`,推荐你使用命令`git add <file>`去将这个文件添加到pool中以备后续commit,或者使用命令`git restore <file>`去忽略这部分改动。`no changes added to commit`没有新的通过add文件到pool中去用于commit。 \ No newline at end of file +step5:🧊使用命令`git status`查看当前仓库内的文件和上一次commit操作后的文件差异,提示在主分支`On branch master`被修改过了,`Changes not staged for commit:`但还没有准备提交的修改文件`modified: readme.txt`,推荐你使用命令`git add <file>`去将这个文件添加到pool中以备后续commit,或者使用命令`git restore <file>`去忽略这部分改动。`no changes added to commit`没有新的通过add文件到pool中去用于commit。 +这是一次没必要的添加 \ No newline at end of file
$ git add readme.txt
$ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: readme.txt
$ 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.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff diff --git a/readme.txt b/readme.txt index b865854..016f23f 100644 --- a/readme.txt +++ b/readme.txt @@ -3,4 +3,5 @@ step1:文件自身的创建是和Git没有关系的,可以用windows的可 step2:🧊使用命令`git add`将任意一个文件添加到Git仓库,可以认为是暂时提交到Git仓库中的一个池子pool中 step3:🧊使用命令`git commit`将前面add操作添加到池子pool中的文件提交到仓库,因此add只能添加一个文件,但是commit可以一次性将pool中的所有文件 提交。 step4:自定义修改文件内容,保存文件内容。 -step5:🧊使用命令`git status`查看当前仓库内的文件和上一次commit操作后的文件差异,提示在主分支`On branch master`被修改过了,`Changes not staged for commit:`但还没有准备提交的修改文件`modified: readme.txt`,推荐你使用命令`git add <file>`去将这个文件添加到pool中以备后续commit,或者使用命令`git restore <file>`去忽略这部分改动。`no changes added to commit`没有新的通过add文件到pool中去用于commit。 \ No newline at end of file +step5:🧊使用命令`git status`查看当前仓库内的文件和上一次commit操作后的文件差异,提示在主分支`On branch master`被修改过了,`Changes not staged for commit:`但还没有准备提交的修改文件`modified: readme.txt`,推荐你使用命令`git add <file>`去将这个文件添加到pool中以备后续commit,或者使用命令`git restore <file>`去忽略这部分改动。`no changes added to commit`没有新的通过add文件到pool中去用于commit。 +这是一次没必要的添加 \ No newline at end of file
现在把工作区的文件修改也撤销了,使用命令git checkout -- readme.txt。
1 2 3 4 5 6
$ git checkout -- readme.txt
$ git status On branch master nothing to commit, working tree clean
$ git status On branch master nothing to commit, working tree clean
手动删除文件,被Git检测到
1 2 3 4 5 6 7 8 9 10 11
$ rm cancel.txt
$ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: cancel.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git reset --hard HEAD^ HEAD is now at 241aeea addfile:cancel.txt
$ rm cancel.txt
$ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: cancel.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git checkout -- cancel.txt
$ git status On branch master nothing to commit, working tree clean