[英]How can I uncommit the last commit in a git bare repository?
考慮到有幾個 git 命令在裸倉庫中沒有意義(因為裸倉庫不使用索引,也沒有工作目錄),
git reset --hard HEAD^
不是取消提交此類存儲庫中最后一次更改的解決方案。
通過互聯網搜索,我能找到的與該主題相關的所有內容是this ,其中介紹了三種方法:
1.“手動更新引用(涉及管道)”;
2.“來自非裸存儲庫的git push -f
”;
3.“ git branch -f this $that
”。
您認為哪種解決方案更合適,或者還有哪些其他方法可以做到這一點? 不幸的是,我發現的關於 git 裸存儲庫的文檔相當糟糕。
您可以使用git update-ref
命令。 要刪除最后一次提交,您可以使用:
$ git update-ref HEAD HEAD^
或者,如果您不在無法刪除最后一次提交的分支中:
$ git update-ref refs/heads/branch-name branch-name^
如果需要,您也可以傳遞 sha1:
$ git update-ref refs/heads/branch-name a12d48e2
請參閱git-update-ref命令的文檔。
如果您在裸倉庫中使用以下內容:
git reset --soft <commit>
那么您就不會遇到在裸--mixed
使用--hard
和--mixed
選項時遇到的問題,因為您不會嘗試更改裸--mixed
沒有的東西(即工作樹和索引)。 在您的情況下,您特別想使用(來自裸倉庫):
git reset --soft HEAD^
要在遠程倉庫上切換分支,請執行以下操作:
git symbolic-ref HEAD refs/heads/<branch_name>
要查看當前選定的分支,請使用:
git symbolic-ref HEAD
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-symbolic-ref.html
git push -f
應該可以正常工作:
如果您克隆該裸倉庫,請刪除最后一次提交( git reset --hard HEAD^
正如您所提到的,但在本地非裸倉庫中)並推回( -f
):
您還可以使用 git refspec 表示法並執行以下操作:
git push -f origin +<commit you want to revert to>:<destination_head | branch_name>
這會強制將目標分支(由 ref 表示)更新到由+<object ref>
部分表示的源提交。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.