git status 查看状态 与 git diff 查看改动

git中如果把仓库里的文件进行了改动, 那么可以用git status 来查看在仓库中哪些文件被改动过, 而且并没有用commit提交为新的版本。


例如我在仓库里的 readme.txt 文件加了一行“git is good”,然后删除一行“Git is free” 然后出去度假,度假回来一脸懵逼不记得之前对当前版本做了什么改动。此时在命令行输入:

git status

程序输出:

D:\Git>git status
On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

表示之前改动了 readme.txt 文件而且这个改动并没有用commit 提交为新版本。


如果我没有进行任何改动,输入

git status

输出:

On branch master
nothing to commit, working tree clean



那么如果我要查看我在这个文件里改动了什么,输入git diff + 文件名来查看此文件的改动有哪些。

git diff readme.txt

输出:

diff --git a/readme.txt b/readme.txt
index 003c7db..6a4c326 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
 Git is cool
-Git is free
+git is good
\ No newline at end of file

表示readme.txt 文件有 Git is cool 删除了Git is free 添加了git is good


而这个改动只参考本次提交的版本(HEAD)如果中间改了很多次也只会和(HEAD)版本里的readme.txt 进行比较。



注: 此文只是完全原创,只作git学习的总结,方便日后查看。

你可能感兴趣的:(git学习笔记,git)