如何从gitlab中删除提交? (Git-恢复无效)
How to delete commits from gitlab? (Git-revert not working)
我正在尝试删除一些错误的 gitlab 提交。
其他线程中提供的答案是
- 点击提交名称
- 点击“选项”
- 点击“还原”
当我尝试删除提交时,它们没有被删除。相反,在顶部创建了两个额外的合并。我确定这是正常的,但我不明白它为什么这样做,更重要的是,它没有删除提交。
如何完全删除提交,以便最后可用的提交是带有超人标志的提交?谢谢
非破坏性的方法就是简单地做你已经做过的事情:恢复你的提交。当然还有“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
分支
我正在尝试删除一些错误的 gitlab 提交。
其他线程中提供的答案是
- 点击提交名称
- 点击“选项”
- 点击“还原”
当我尝试删除提交时,它们没有被删除。相反,在顶部创建了两个额外的合并。我确定这是正常的,但我不明白它为什么这样做,更重要的是,它没有删除提交。
如何完全删除提交,以便最后可用的提交是带有超人标志的提交?谢谢
非破坏性的方法就是简单地做你已经做过的事情:恢复你的提交。当然还有“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-rollback
分支
master