分佈式版本控制系統在日常開發中使用越來越頻繁,誰沒經歷過手一抖,不小心把錯誤的內容git push到遠程倉庫?
前幾天我就遇到了,當時對git也不熟,於是各種try……終於,現在搞明白了
環境:
遠程倉庫fork的開發項目
分支只有master
操作:
git pull origin master (埋下禍根,把別人的commit也pull下來了)
git push self master:master
repo中merge 請求,包含別人的commit !
解決辦法:
新建臨時分支git checkout -b newMaster
版本退回 git reset beaforeYourCommitNum (不要用--hard哈)
git add * ;git commit - m "blabla..."
git pull --rebase origin master
git push self master:newMaster
repo中,找到setting,更改defalt branch 爲 newMaster(沒有強迫症童鞋的可以到此爲止哈,一下操作爲改主分支爲master)
repo 和 本地 都刪除master
git push self master:master (創建新的遠程master)
repo 和 本地 都刪除newMaster git branch -d newMaster ()
以上是本人血的教訓(週六加班,沒過好~),歡迎大家學習指教,願上帝祝福大家!