lzh@ubuntu:~/workspace/learngit$ git status On branch master nothing to commit, working tree clean
这表示没有需要提交的更改。我们修改一下 readme.txt 的内容,再查看一次:
1 2 3 4 5 6 7 8 9 10
lzh@ubuntu:~/workspace/learngit$ 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")
lzh@ubuntu:~/workspace/learngit$ git diff readme.txt diff --git a/readme.txt b/readme.txt index 1f45bc7..ebf599b 100644 --- a/readme.txt +++ b/readme.txt @@ -1 +1,2 @@ -it's a readme file. \ No newline at end of file +it's a readme file. +Edit for the first time. \ No newline at end of file
lzh@ubuntu:~/workspace/learngit$ git add readme.txt lzh@ubuntu:~/workspace/learngit$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
modified: readme.txt
lzh@ubuntu:~/workspace/learngit$ git commit -m "modify readme.txt" [master 6cc166a] modify readme.txt 1 file changed, 2 insertions(+), 1 deletion(-) lzh@ubuntu:~/workspace/learngit$ git status On branch master nothing to commit, working tree clean
版本回退
每次 commit ,就像是进行了一次快照。我们可以选择从一次 commit 中恢复。
使用 git log 查看:
1 2 3 4 5 6 7 8 9 10 11 12 13
lzh@ubuntu:~/workspace/learngit$ git log commit 6cc166a21e5630e8d3a0151ee331c04c5ac2c251 (HEAD -> master) Author: amjac <amjac_lzh@163.com> Date: Sun Jan 5 23:35:38 2020 -0800
modify readme.txt
commit f9ab921e9c9c17eda1038254e0c893c9e0fbe451 Author: amjac <amjac_lzh@163.com> Date: Sun Jan 5 23:19:58 2020 -0800
lzh@ubuntu:~/workspace/learngit$ 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
Untracked files: (use "git add <file>..." to include in what will be committed)
LICENSE
no changes added to commit (use "git add" and/or "git commit -a")
lzh@ubuntu:~/workspace/learngit$ git reset HEAD readme.txt Unstaged changes after reset: M readme.txt lzh@ubuntu:~/workspace/learngit$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
new file: LICENSE
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
然后再用 git checkout 来撤销工作区的修改,退回版本库。
删除文件
在文件管理器中,将没用的文件删除,使用命令 rm 。但此时,工作区和版本库变得不一致了。git status 命令会告诉你哪些文件被删除了。
1 2 3 4 5 6 7 8 9 10 11
lzh@ubuntu:~/workspace/learngit$ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
deleted: LICENSE modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")