git - 如何撤消两次提交之间的更改?
问题描述
我想在两次提交之间恢复一个文件更改,
commit 1 hash: abcde1....
some code changes
commit 2 hash : abcde2....
some code changes
commit 3 hash : abcde3....
some code changes
.....
我可以使用git checkout abcde3 -- file/to/restore
并恢复到提交 3,但丢失了提交 1 更改,
我如何才能仅签出提交 2 更改?
解决方案
您可以简单地使用git revert
.
恢复提交 2,这将创建一个新的提交,取消由所述提交 2 引入的任何更改。
如果git revert
(在提交级别运行,并且not
对于单个文件)恢复了太多文件,您可以重置您不想恢复的文件。
git revert --no-commit <commit hash> # Revert, don't commit it yet
git reset # Unstage everything
git add yourFilesToRevert # Add the file to revert
git commit -m "commit message"
git reset --hard # Undo changes from the part of the revert that we didn't commit
推荐阅读
- leaflet - 带有传单的 mbtiles 文件
- dart - Flutter 导航堆叠
- python - 如何配置 kubernetes pod,使用 pod 创建 pod?
- java - 具有自定义大小的 Android Surface 视图
- sqlite - Perl dancer错误执行方法未定义
- android - 如何从 Android React Native 中的文本文件中读取数据?
- mysql - MTSQL Rollup 连接表错误
- python - Selenium driver.get() 抛出异常
- java - 如何将 HTML 目录上传到 Spring 服务器,然后创建链接以查看该目录中的 index.html 文件
- r - 在R中查找每个列表中的最后一个数字是偶数还是奇数