开发和UAT。 开发是我们开发的分支,UAT是实时服务器。
我把一些文件从dev推到了UAT。
现在我想将推送到UAT的文件(有错误)还原到以前的UAT工作副本。
我该怎么做?
我对以下命令感到困惑:
git reset --soft HEAD~1
git revert HEAD
答案 0 :(得分:1)
另一方面,如果您已发布该作品,您可能不想重置该分支,因为它有效地重写了历史记录。在这种情况下,您确实可以还原提交。使用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