更改暂存的文件

如果在提交之前更改其中一个暂存文件,则需要将更改再次添加到暂存区域,以提交新更改。这是因为Git创建了暂存文件内容的快照。必须再次进行所有新的更改。

1
2
3
4
5
# append a string to the test03 file
echo "foo2" >> test03

# see the result
git status

验证新更改尚未暂存。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
On branch master

Initial commit

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: datafiles/data.txt
new file: test01
new file: test02
new file: test03

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: test03

将新更改添加到暂存区域。

1
2
# add all files to the index of the Git repository
git add .

git status再次使用该命令可以查看所有更改是否已暂存。

1
2
3
4
5
6
7
8
9
10
11
On branch master

Initial commit

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: datafiles/data.txt
new file: test01
new file: test02
new file: test03
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×