Git将推送的更改还原为上一次提交

Git将推送的更改还原为上一次提交,git,Git,开发和UAT。 其中开发是我们开发的一个分支,UAT是实时服务器 我把一些文件从dev推送到UAT 现在我想将推送到UAT的文件(有错误)恢复到UAT的前一个工作副本 我该怎么做 我对以下命令感到困惑: git reset --soft HEAD~1 git revert HEAD 使用新提交撤消已发布的提交 另一方面,如果您已经发布了工作,您可能不想重置分支,因为这实际上是在重写历史。在这种情况下,您确实可以恢复提交。对于Git,revert有一个非常具体的含义:使用反向补丁创建提交以取消

开发和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
其中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

.

重置移动标签可能重复。Revert添加提交撤消更改。
# 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