我有一個關于 git 和 GitHub 的初學者問題,希望有人能提供幫助。
我不小心對包含本地計算機上本地私有存盤庫憑據的代碼進行了更改。
我的偽提交歷史如下所示,我正在使用 GitHub 的桌面應用程式進行這些提交。我在 id 3 犯了錯誤的提交,但是我從 4 到 7 的所有其他提交都是大量的作業,我不希望失去它們。
由于這是我自己的存盤庫,因此快速的方法可能是簡單地復制我更改的檔案并將所有更改恢復為 id 3,然后復制我更改好的檔案。我想知道是否有更好的Git方法
commit first change id 1
commit second change id 2
commit third change id 3 - here is where the password was committed
commit first change id 4
commit second change id 5
commit first change id 6
commit second change id 7
非常感謝您的寶貴時間
uj5u.com熱心網友回復:
因為你也標記了 GitHub。請務必聯系 GitHub 支持,讓他們從他們的問題和 PR 鏈接以及快取中洗掉提交。
重設密碼。一旦按下密碼就在那里。
官方流程將是:
Git clone --mirror回購的新副本。確保你擁有一切git filter-repo從所有提交中洗掉密碼- 然后運行垃圾收集器以洗掉所有未參考的提交:
git reflog expire --expire=now --all && git gc --prune=now --aggressive --mirror然后使用該選項強制推送回購。- 然后聯系 GitHub 支持從快取中洗掉舊的提交。
- 然后聯系所有其他貢獻者以獲取新的克隆,以將其分支重新定位到更新的存盤庫中。
uj5u.com熱心網友回復:
你可以做壁球:
git rebase -i <commit_id or HEAD~5>
# move your cursor on the commit line & delete that commit by pressing double `d`
git push -f origin <branch>
它有助于僅洗掉選定的提交,而無需在該提交之后和之前更改提交。
或者,軟重置和提交:
git reset --soft <commit_id or HEAD~5>
git add .
git commit -m "<message>"
git push -f origin <branch>
它從 中洗掉所有提交commit_id or HEAD~5并進行一次提交。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428338.html
