版本管理

查看状态

首先使用git status查看下

1
2
3
$ git status
On branch master
nothing to commit, working tree clean

将文件更改为

1
2
test1
test11

再使用git status查看下

1
2
3
4
5
6
7
$ 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: test1.txt
no changes added to commit (use "git add" and/or "git commit -a")

git diff查看修改
git add test1.txt提交修改

版本回退

回退到上一个版本add distributed,就可以使用git reset命令:

$ git reset --hard HEAD^

回退多个版本

$ git reset --hard "commit id"

回到新版本

如果还能找到”commit id”,就像回退一样的操作。
如果找不到”commit id”,使用git reflog查看命令历史。

撤销修改

修改了文件,还没有git add,可以使用
git checkout -- file

如果git add后,使用
git reset HEAD <file>