恢复文件的历史版本 git revert
- 创建一个
css目录,添加一个index.css文件,在index.html文件里引入git add .git commit -m '在index.html 文件里引入 css目录下的index.css文件' - 创建一个
js目录,添加一个index.js文件,在index.html文件里引入git add .git commit -m '在index.html 文件里引入 js目录下的index.js文件' -
git log --oneline简短一行展示提交过的日志
09a6611 (HEAD -> master) 合并首页
fcf34d7 添加git7.md
c379c9e Revert "git rm 和 git checkout HEAD ^ 的使用"
-
git revert fcf34d7id号为上面log前面的ID:wq保存提交
Revert "添加git7.md"
This reverts commit fcf34d7c92246c347dbcf3fc89a7ae84fa699164.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
# modified: git7.md
-
git log --oneline会发现刚刚提交的内容 变成以前那个版本了
47734fe (HEAD -> master) Revert "添加git7.md"
09a6611 合并首页
fcf34d7 添加git7.md
c379c9e Revert "git rm 和 git checkout HEAD ^ 的使用"
指针指向最后一次提交 git reset
-
--soft软重置 不会影响暂存区和工作区的东西 -
--hard把暂存区和工作区直接重置到提交的状态 -
--mixed重置到提交的状态把暂存区,并把指针指向这个提交
操作:
git log --oneline
09a6611 合并首页
fcf34d7 添加git7.md
c379c9e Revert "git rm 和 git checkout HEAD ^ 的使用"
-
git reset --soft fcf34d7指针指向fcf34d7
fcf34d7 (HEAD -> master) 添加git7.md
c379c9e Revert "git rm 和 git checkout HEAD ^ 的使用"
0e851ce fix
git reset --hard 09a6611
09a6611 合并首页
fcf34d7 添加git7.md
c379c9e Revert "git rm 和 git checkout HEAD ^ 的使用"