返回
Git 使用教程:审阅更改并修改内容
后端
2023-12-08 19:57:50
现在我们已经完成了文件的添加,是时候审阅更改并进行任何必要的修改了。Git 提供了多种命令来帮助我们完成此任务。
查看文件状态
要查看文件的状态,可以使用 git status
命令。此命令将显示一个列表,列出已修改、已暂存和未跟踪的文件。
git status
该命令输出类似于以下内容:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: README.md
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: example.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
.idea/
此输出告诉我们:
README.md
是一个新文件,已添加到暂存区。example.txt
已被修改,但尚未暂存。.idea/
是一个未跟踪的目录。
修改内容
如果我们想修改文件,可以使用文本编辑器打开文件并进行更改。对于 example.txt
,我们可以使用以下命令:
vim example.txt
保存更改后,可以使用 git add
命令将更改暂存到版本库中。
git add example.txt
现在,如果我们再次运行 git status
命令,我们会看到以下输出:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: README.md
modified: example.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
No untracked files found
这表明 example.txt
中的更改已成功暂存。
总结
查看文件状态和修改内容是 Git 工作流程的重要部分。通过使用 git status
和 git add
命令,我们可以轻松地跟踪更改并确保只提交我们想要的内容。