如何撤消合并请求及其提交



我在gitlab上对分支develop执行了merge request。然后我意识到我犯了一个巨大的错误。我迅速按下revert按钮,心想一切都好,但不是。Gitlab只提交了revert。在日志中,仍然有来自源分支的提交。它会导致版本出现许多问题。有没有任何方法,任何解决方案可以在gitlab平台上恢复单个合并请求,并从许多不需要的提交中清除分支日志。我希望我的分支机构像这样合并请求从来没有位置。

首先创建一个新的分支keepsafe,使所有这些更改都保留在某个位置,以防出现问题。这将";复制";本地显示当前状态,并将其保存在远程。

git checkout -b keepsafe
git push

现在回去发展。X是您希望删除的提交数。

git checkout develop
git reset --hard HEAD~X
git push -f

将本地开发硬重置为原始提交。git push -f将覆盖远程分支。所有提交都将消失。

请注意,GitLab允许管理员禁用强制推送(git push-f(,因此如果这不起作用,您需要与管理员交谈。

您可以使用交互式rebase恢复到以前的提交。假设您想将HEAD恢复为HEAD~5(之前有5次提交(,您可以选择HEAD~5的父级,即HEAD~6,并在其顶部应用HEAD~5。

git rebase -i HEAD~6

HEAD~6到HEAD之间的每个提交都将被重写。假设HEAD~5SHA1是ABC&头~6 SHA1是XYZ。当前HEAD为PQR。我们需要从下面的编辑中删除其他提交,因为我们不想在HEAD~6上重写它们。我们只想在HEAD~6之上应用HEAD~5。我们应该在这个文件中至少有一个条目,否则rebase将中止。因此,我们在HEAD~6之上应用HEAD~5。

edit ABC     reverting to state before merge 
# Rebase XYZ..PQR onto XYZ
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

现在,发出以下命令来修改历史记录并输入提交消息。

git commit --amend

现在,发出以下命令继续并退出编辑器

git commit --continue

阅读有关重写git历史的更多信息

最新更新