git status

git status命令可以列出当前目录所有还没有被git管理的文件和被git管理且被修改但还未提交(git commit)的文件.。
比如;
git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   2.txt
#
# 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:   1.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       1.log
命令中”Changes to be committed“中所列的内容是在Index中的内容,commit之后进入Git Directory。
命令中“Changed but not updated”中所列的内容是在Working Directory中的内容,add之后将进入Index。
命令中“Untracked files”中所列的内容是尚未被Git跟踪的内容,add之后进入Index
通过git status -uno可以只列出所有已经被git管理的且被修改但没提交的文件。
比如:
$ touch 3.txt
$ git add 3.txt
git status -uno
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   1.txt
#       new file:   3.txt
#
# 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:   2.txt
#
# Untracked files not listed (use -u option to show untracked files)
这里1.txt,2.txt两个文件都是曾经被提交过的文件。
1.txt被修改且被执行了git add。
2.txt被修改但还没被执行了git add。
3.txt是新建的文件,已经被执行了git add。
另外注意,我们可以通过git add -i 命令查看<path>中被所有修改过或已删除文件但没有提交的文件,它有类似git status的功能
### `git status` 命令的作用和使用方法 `git status` 是 Git 中用于查看当前工作目录和暂存区状态的重要命令。它可以显示哪些文件已经被暂存(staged),哪些文件在工作目录中被修改但尚未暂存,以及哪些文件未被 Git 跟踪[^1]。该命令不会显示已经提交到项目历史中的信息,如需查看历史记录,应使用 `git log`。 执行 `git status` 后,输出通常分为以下几个部分: - **Changes to be committed**:这部分列出已经通过 `git add` 添加到暂存区的更改,等待下一次提交。 - **Changes not staged for commit**:这部分列出在工作目录中已被修改但尚未添加到暂存区的文件。 - **Untracked files**:这部分列出尚未被 Git 跟踪的文件,即从未被添加过的文件或目录。 以下是一个典型的使用示例: ```bash git status ``` 输出可能如下所示: ``` On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: README.md 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: src/main.py Untracked files: (use "git add <file>..." to include in what will be committed) new_file.txt ``` 此输出表明: - `README.md` 已经被暂存,准备提交。 - `src/main.py` 在工作目录中被修改但尚未添加到暂存区。 - `new_file.txt` 是一个未被跟踪的新文件。 可以通过以下方式对状态进行操作: - 使用 `git add <file>` 将文件添加到暂存区。 - 使用 `git restore <file>` 放弃工作目录中的更改。 - 使用 `git restore --staged <file>` 取消暂存某个文件[^4]。 如果希望将所有更改一次性添加到暂存区,可以使用: ```bash git add . ``` 该命令会将当前目录及其子目录下的所有修改、新增文件加入暂存区[^1]。 若想仅查看某些特定类型的文件状态,也可以结合通配符使用,例如: ```bash git status *.txt ``` 这将只显示 `.txt` 文件的状态信息。 此外,在执行 `git reset --soft` 后,自上次提交以来的所有更改都会显示在 `git status` 的 “Changes to be committed” 部分中[^3]。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值