..." to">..." to update what will be committed) (use "git checkout -- &_on branch mas">
赞
踩
git管理的一些命令
修改read.txt文件为:
Git is a distributed version control system.
Git is free software.
命令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: read.txt
no changes added to commit (use "git add" and/or "git commit -a")
上面命令告诉我们read.txt被修改过,还没有提交
查看具体如何修改了git diff read.txt
index 99e0e11..013b5bc 100644
--- a/read.txt
+++ b/read.txt
@@ -1,2 +1,2 @@
Git is a distributed version control system.
-Git is free software distributed under the GPL.
\ No newline at end of file
+Git is free software.
\ No newline at end of file
可以看到是第二行做了怎样的修改。
然后可以放心的把read.txt使用git add
和git commit
提交到仓库。
回到过去
每一个提交到仓库的版本叫做一个commit
命令git log
可以显示从最近到最远的提交日志
可以看到这里有三个提交的版本
获得更精简的版本信息$ git log --pretty=oneline
前面一大串的字符为commit id
版本号
现在要回到上一个版本使用命令git reset
$ git reset --hard head^
HEAD is now at 329c0f5 add distributed
现在查看当前内容
$ cat read.txt
Git is a distributed version control system.
Git is free software.
内容被还原。
现在再使用git log
查看版本信息
发现只有两个版本了,最新的版本看不到了。如果想再回到最新的版本办法也是有的:通过commit id
版本号前几位还原。
$ git reset --hard a098
HEAD is now at a0982c2 append GPL
注意:如果版本很多版本号前几位可能重复,尽量多打几位。
如果隔天想回到最新版本,命令git reflog
记录了你每一次的操作,找到版本号如上进行还原。
总结:
1.git status
查看仓库当前状态
2.假如有修改,git diff
查看修改信息
3.git log
查看版本信息 加--pretty=oneline
参数可查看精简版本信息
4.git reflog
查看命令历史,可用于回到最新版本
5.git reset
切换版本 有两种使用方法
①按顺序:后加 head^
回退一个版本head^^
回退两个版本以此类推
②根据版本号:后加版本号前几位即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。