查看当前仓库状态
运行git status
命令可以查看结果:
MacBook-Pro-2% git status
On branch master
nothing to commit, working tree clean
git status
可以让我们时刻掌握仓库当前状态,上面的命令告诉我们在上次提交后没有被修改的文件
,那么我们修改后再试试看:
MacBook-Pro-2% git status
On branch master
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: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
MacBook-Pro-2%
这里没有显示修改的内容,如果能看什么被修改了但是没提交那是极好的。所以我们需要git diff
这个命令来看看:
MacBook-Pro-2% git diff
diff --git a/readme.txt b/readme.txt
index 884b2bc..0b138d6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,3 @@
this is the readme file for myweb
i can learn web by practice!
+we can show our reaserch result though web tech!
我们在这里可以看到readme.txt文件被修改了,并且知道了修改了什么内容,接下来就可以先用git add
再用git commit
来提交修改了:
MacBook-Pro-2% git add readme.txt
MacBook-Pro-2% git commit -a
Aborting commit due to empty commit message.
MacBook-Pro-2% git commit -m "add distributed"
[master 130362a] add distributed
Committer: Chenjun Xiong <ChadwinSean@MacBook-Pro-2.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
MacBook-Pro-2% git status
On branch master
nothing to commit, working tree clean
MacBook-Pro-2%
这次我们学习了git status
与git diff
的使用。