如何删除我所做的提交GitLab?我做的这个提交现在不是HEAD.
如果我无法删除它,我可以编辑吗?
当它是HEAD时,我试过:
git reset --soft HEAD
git reset --soft HEAD^1
git revert HEAD
git rebase -i HEAD
git rebase -i HEAD~1
git reset --hard HEAD
git reset --hard Id-Code
Run Code Online (Sandbox Code Playgroud)
我已经试图改变它,但它仍然留在分支上.现在我把它从HEAD中删除了,但它仍然存在.
有另一个命令?
Álv*_* P. 28
假设你有以下场景:
* 1bd2200 (HEAD, master) another commit
* d258546 bad commit
* 0f1efa9 3rd commit
* bd8aa13 2nd commit
* 34c4f95 1st commit
Run Code Online (Sandbox Code Playgroud)
你想要删除d258546,即"错误提交".
您将尝试使用交互式rebase删除它: git rebase -i 34c4f95
然后你的默认编辑器会弹出这样的东西:
pick bd8aa13 2nd commit
pick 0f1efa9 3rd commit
pick d258546 bad commit
pick 1bd2200 another commit
# Rebase 34c4f95..1bd2200 onto 34c4f95
#
# 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
Run Code Online (Sandbox Code Playgroud)
只需删除要删除的提交行,然后保存+退出编辑器:
pick bd8aa13 2nd commit
pick 0f1efa9 3rd commit
pick 1bd2200 another commit
...
Run Code Online (Sandbox Code Playgroud)
git将继续从您的历史记录中删除此提交,留下类似这样的内容(请记住已删除提交的提交后代中的哈希更改):
* 34fa994 (HEAD, master) another commit
* 0f1efa9 3rd commit
* bd8aa13 2nd commit
* 34c4f95 1st commit
Run Code Online (Sandbox Code Playgroud)
现在,因为我认为你已经将错误的提交推送到gitlab,你需要将你的图表重新存储到存储库(但是有一个-f选项可以防止它因为非快速的历史记录而被拒绝git push -f <your remote> <your branch>)
请格外小心,确保没有同事已经在其分支中使用包含"错误提交"的历史记录.
备选方案:
您可以简单地创建一个新的提交来否定您的错误提交所引入的更改,而不是重写历史记录git revert <your bad commit hash>.这个选项可能不是很干净,但更安全(如果你不完全清楚你在使用交互式rebase做什么).
ABH*_*HRI 21
1.git reset --hard CommitId
2.git push -f origin master
第一个命令会将你的头放在commitid上,第二个命令将删除master分支上的commit id之后的所有提交.
小智 12
我们遇到了类似的问题,仅删除提交并强制推送到 GitLab 是不够的。
它仍然可以在 GitLab 界面中使用 url 使用:
https://gitlab.example.com/<group>/<project>/commit/<commit hash>
Run Code Online (Sandbox Code Playgroud)
我们不得不从 GitLab 中删除项目并重新创建它以摆脱 GitLab UI 中的这个提交。
| 归档时间: |
|
| 查看次数: |
65152 次 |
| 最近记录: |