本篇内容主要讲解“git撤销的用法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“git撤销的用法”吧!
撤销本地修改
[root@xuhx-02 git_project]# git status
# 位于分支 master
# 尚未暂存以备提交的变更:
# (使用 "git add <file>..." 更新要提交的内容)
# (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
# 修改: README.md
#
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
[root@xuhx-02 git_project]# git checkout -- README.md
[root@xuhx-02 git_project]# git status
# 位于分支 master
无文件要提交,干净的工作区
撤销git add
[root@xuhx-02 git_project]# git add 01.sh
[root@xuhx-02 git_project]# git status
# 位于分支 master
# 要提交的变更:
# (使用 "git reset HEAD <file>..." 撤出暂存区)
#
# 新文件: 01.sh
#
[root@xuhx-02 git_project]# git reset HEAD 01.sh
[root@xuhx-02 git_project]# git status
# 位于分支 master
# 未跟踪的文件:
# (使用 "git add <file>..." 以包含要提交的内容)
#
# 01.sh
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
撤销commit
[root@xuhx-02 git_project]# git commit -m "add 01.sh"
[master 9d8cbe9] add 01.sh
1 file changed, 10 insertions(+)
create mode 100644 01.sh
[root@xuhx-02 git_project]# git reset --mixed HEAD^
[root@xuhx-02 git_project]# git status
# 位于分支 master
# 未跟踪的文件:
# (使用 "git add <file>..." 以包含要提交的内容)
#
# 01.sh
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
[root@xuhx-02 git_project]# git reset --soft HEAD^
[root@xuhx-02 git_project]# git status
# 位于分支 master
# 要提交的变更:
# (使用 "git reset HEAD <file>..." 撤出暂存区)
#
# 新文件: 01.sh
#
[root@xuhx-02 git_project]# git reset --hard f51b0fdfa6846f88b90ac76e7975594bdd887576
HEAD 现在位于 f51b0fd add readme
[root@xuhx-02 git_project]# ls
README.md
# 重新提交
$ git add sample.txt
$ git commit --amend -m"说明"
清除工作空间 git clean
[root@xuhx-02 git_project]# git clean -n
将删除 01.sh
参考git 撤销回滚学习
到此,相信大家对“git撤销的用法”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!