【Git】查看文件变更状态的方法是使用git status命令
以前我发过这样的推文。在执行git add和git commit之前,我知道需要使用git status命令,但不知道具体如何使用。因此,在这篇文章中我会解释git status的详细用法。
我平时分享编程和自由职业的内容。关注一下吧。
在执行git add或git commit之前,务必先使用git status命令确认哪些文件已经被修改,然后养成git add和git commit的习惯。
确认变更情况
使用 git status 命令来查看更改状态。
命令行
> git status
Git状态的使用方式
在工作目录和分支之间更改的文件是指“在使用git add命令添加之后再修改的工作目录文件”。
在阶段和代码库之间更改的文件,“添加到 git commit 后添加到阶段的文件”。
它会给我展示每一个。
确认变更状态
在将index.html文件添加到暂存区后,执行git status命令的情况下。
命令行
> git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html
让我们对index.html文件进行一些修改,然后执行git status命令。
命令行
> git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html
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: index.html
然后,显示出了一些未被添加到舞台上的更改。
只需提供一种选择:
显示修改的文件为index.html。
我们将使用 git add 将此文件添加到暂存区中,并使用 git status 进行确认。
命令行
> git add index.html
> git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html
下面显示的是要提交的更改:这意味着存在应该提交的内容。
当谈及哪个文件的时候,显示着应该提交的内容是新文件: index.html。
让我们接下来提交并确认这个文件。
命令行
> git commit -m "statusコマンドの確認"
[master 0420876] statusコマンドの確認
1 file changed, 2 insertions(+)
create mode 100644 index.html
> git status
On branch master
nothing to commit, working tree clean
使用git commit命令对文件进行提交
当我运行git status命令进行确认时,显示当前没有需要提交的更改。
请养成这样的习惯:在修改文件后,请用git status命令确认哪些文件已被更改,然后再使用git add或git commit。