iT邦幫忙

0

github reset設定

  • 分享至 

  • xImage

我有一個專案他的最新commit已經push到github上了,但是我想要恢復到上一個commit,但是只能動main以外的branch使用--force強制上傳,請問一下,有什麼方法可以解決這個問題?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
EN
iT邦好手 1 級 ‧ 2022-10-24 22:11:40

git revert

0
Kailis
iT邦研究生 1 級 ‧ 2022-10-25 11:03:33

git 新手的話, 這個網站有很多練習題可以嘗試

1
iT邦新手 2 級 ‧ 2022-10-25 19:30:30

可能是你的專案有設定保護機制,鎖住了。
參考:【狀況題】聽說 git push -f 這個指令很可怕,什麼情況可以使用它呢?

但我會建議不要用 force push,除非是那個部分一定一定得覆蓋掉,再使用。


我會建議就讓歷史保留在那,用 revert 的方式,恢復到你要的狀態,在最上面新增一個 commit 註記在此做了 revert。
參考:How can I revert multiple Git commits?

// EX.
// 假設你最新的 commit 是 xxxxxx7,最舊的是 xxxxxx1
// 你想移除 xxxxxx7 ~ xxxxxx2

$ git revert --no-commit xxxxxx1..
$ git commit -m  "[REVERT] 移除 xxxxxx7 ~ xxxxxx2 的內容"

我要發表回答

立即登入回答