git - Git 将推送的更改恢复为先前的提交
问题描述
开发和 UAT。开发是我们开发的一个分支,而 UAT 是实时服务器。
我已经将一些文件从 dev 推送到 UAT。
现在我想将推送到 UAT 的文件(有错误)恢复为 UAT 的先前工作副本。
我该怎么做呢?
我对以下命令感到困惑:
git reset --soft HEAD~1
git revert HEAD
解决方案
使用新提交撤消已发布的提交
另一方面,如果您已经发布了作品,您可能不想重置分支,因为这实际上是在重写历史。在这种情况下,您确实可以还原提交。对于 Git,revert 有一个非常具体的含义:创建一个带有反向补丁的提交以取消它。这样你就不会重写任何历史。
# This will create three separate revert commits:
git revert a867b4af 25eee4ca 0766c053
# It also takes ranges. This will revert the last two commits:
git revert HEAD~2..HEAD
#Similarly, you can revert a range of commits using commit hashes:
git revert a867b4af..0766c053
# Reverting a merge commit
git revert -m 1 <merge_commit_sha>
# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 0d1d7fc32 .
# Then commit. Be sure and write a good message describing what you just did
git commit
要恢复到以前的提交,忽略任何更改:
git reset --hard HEAD
其中 HEAD 是当前分支中的最后一次提交。
# Resets index to former commit; replace '56e05fced' with your commit code
git reset 56e05fced
# Moves pointer back to previous HEAD
git reset --soft HEAD@{1}
git commit -m "Revert to 56e05fced"
# Updates working copy to reflect the new commit
git reset --hard
学分。
推荐阅读
- android - android studio中的菱形
- databricks - Databricks SQL:为什么左连接中的子查询导致错误消息
- highcharts - 在 highcharts 热图 xaxis 上显示 20 多个类别
- gradle - 如何使用“dependsOn”执行 Zip 类型的任务?
- visual-studio - 由于缺少某些内容,无法保存书架集
- javascript - 如何通过单击按钮添加html输入
- reactjs - razzle 无法解析“fs”/“net”(服务器端渲染反应应用程序)
- json - JQ获取终端唯一值并按键过滤
- c# - 统一引用和更改网格渲染器上的材质
- node.js - NodeJs 在控制台中处理用户输入