簡體   English   中英

如何將我的 GitHub 提交恢復到前一個?

[英]How to revert back my GitHub commit to the previous one?

我有一個私有的 GitHub 存儲庫。 我只推送到主分支,並且我是唯一有權訪問存儲庫的人。

在此處輸入圖像描述

我想恢復 4 天前的內容(到 2020 年 12 月 5 日的提交)並且最后一次提交(5 小時前)消失。

我在推送到 git 時使用了以下命令。

   git add notes.org
   git commit -m "Sync"
   git push

我將不勝感激任何建議。 謝謝!

要刪除新提交的所有痕跡,您需要將分支重置回不包含該內容的早期 state(提交)。 如果您只是刪除第一個最近的提交,您可以這樣做

# switch to your branch
git switch your-branch

# reset your branch hard to point to the (1) most recent commit
git reset --hard your-branch~1

# push the new state of your branch to the server forcefully
git push your-remote your-branch --force-with-lease

您可以使用以下兩個命令刪除最后一次提交,並強制 github 與您的匹配。

git reset --hard HEAD^
git push origin -f

如果第二個命令不起作用,請嘗試

git push --force origin main

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM