git - 如何在 git pull 之后将本地仓库恢复到上一个提交?
问题描述
假设 git pull 命令将我的本地 repo 推进几个提交以匹配远程 repo,并且我希望本地 repo 在 git pull 之前返回到提交 ID。换句话说,我想撤销我从 git pull 得到的一切。我应该使用哪个命令?
解决方案
要切换回分支,只需检查拉取请求输出中列出的 Git 提交:
$ git pull
Updating d5c40ea5e..29f1ae2b3
Fast-forward
README.md | 15 +++++++++++++++
gradle.properties | 2 +-
2 files changed, 16 insertions(+), 1 deletions(-)
请注意d5c40ea5e
此更新自。只需检查这个分支,代码就会回到拉取请求之前的状态。
$ git checkout d5c40ea5e
Note: switching to 'd5c40ea5e'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at d5c40ea5e Update code to be super awesome
推荐阅读
- python - pip/python3 - macOS:安装 virtualenv 时出现混合消息
- python - Spotify 中的错误。出了点问题,请重试或查看我们的帮助区
- php - Symfony 3、Xdebug 和 NetBeans 10 配置
- python - 定义一个函数来解析一个电子邮件地址
- sublimetext3 - 无法使用 Sublime text 3.1.1 将远程文件打开到本地
- api - 如何在同一视频查询中连接两个“videoCategoryId”?
- powershell - 以管理员权限运行 PowerShell 脚本并绕过执行策略
- typescript - 如何根据数组的值定义类型?
- pyqt - Pyqt Custom QPolygon 被删除:RuntimeError: Wrapped C/C++ object of type ImagePolygon has been deleted
- ios - 如何与自定义 UICollectionViewCell 单元格交互