gpt4 book ai didi

git - 如何从gitlab中删除提交? (Git-revert 不工作)

转载 作者:行者123 更新时间:2023-12-05 02:11:19 26 4
gpt4 key购买 nike

我正在尝试删除一些错误的 gitlab 提交。

其他线程中提供的答案是

  1. 点击提交名称
  2. 点击“选项”
  3. 点击“还原”

当我尝试删除提交时,它们并没有被删除。相反,在顶部创建了两个额外的 merge 。我确定这是正常的,但我不明白它为什么这样做,更重要的是,它没有删除提交。

如何完全删除提交,以便最后可用的提交是带有超人标志的提交?谢谢

最佳答案

非破坏性的方法就是简单地做你已经做过的事情:恢复你的提交。当然还有“2 次提交”,但是您的分支处于与以前相同的状态

破坏性的方法是删除提交,但这会覆盖你的分支历史。因此,您需要额外的权限来重写分支历史记录。

Before to go further, you need to understand that:

  • Depending on the repository configuration you may NOT be allowed to do such a thing
  • You'll force everybody else working on this repository to force pull the branch, therefore they may loose their work if they're not well understanding the process
  • You'll loose EVERY commit after the superman one, even those that would have been created by someone else in the last hours

I highly recommend you to NOT do this.

根据代码,假设这是分支 master:

# Retrieve the latest version
git pull origin master
# Goes back to the superman commit
git reset --hard 329a7a0e
# Force push to rewrite history
# Will be refused if the branch is protected
git push origin master --force

对于 Gitlab,我认为你别无他法:

  • 329a7a0e 提交创建一个新分支,命名为 master-rollback
  • 删除master分支
  • master-rollback创建一个新分支master
  • 删除master-rollback分支

关于git - 如何从gitlab中删除提交? (Git-revert 不工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57626478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com