問(wèn)題描述
在開(kāi)發(fā)的過(guò)程中,想要修改一個(gè)參數(shù)的命名。然后修改各種地方,并且push上碼云的遠(yuǎn)程倉(cāng)庫(kù)。然后突然發(fā)現(xiàn)還要改很多地方,突然后悔不想改動(dòng)了。那該怎么辦呢?
處理步驟
- 回退本地的git版本
- 將本地的代碼強(qiáng)制推送至遠(yuǎn)程倉(cāng)庫(kù)中
回退本地git版本
- 首先查看git版本信息,使用
git log
$ git log
commit 6fecbc4fc9d7e23f5c66a504a413cc1ed4ed7f0c (HEAD -> master, origin/master,origin/django-template, origin/HEAD, django-template)
Author: kubernete <357018097@qq.com>
Date: Thu Aug 15 22:24:16 2019 +0800
修改table行數(shù)的參數(shù)名為table-lines
commit 0e149c39eb4401647a9468eaf2b68b45832dbcb2
Author: kubernete <357018097@qq.com>
Date: Thu Aug 15 22:05:07 2019 +0800
取消tab菜單的360度翻轉(zhuǎn)動(dòng)畫(huà)效果
commit 7c4b1492616ae788e9f58461c72fc12f6c9b1e2d
Author: lijw <357018097@qq.com>
Date: Thu Aug 15 19:44:24 2019 +0800
編寫(xiě)設(shè)備機(jī)組列表中查詢隱藏域填充顯示table行數(shù)
看了上面的git提交日志,我不想要修改table行數(shù)的參數(shù)名為table-lines這次的代碼提交,想直接回退到取消tab菜單的360度翻轉(zhuǎn)動(dòng)畫(huà)效果的版本。
那么可以直接執(zhí)行回退到上一版本。
- 執(zhí)行回退到上一版本,使用
git reset --hard HEAD^
# 執(zhí)行回退至上一次提交的版本
$ git reset --hard HEAD^
HEAD is now at 0e149c3 取消tab菜單的360度翻轉(zhuǎn)動(dòng)畫(huà)效果
# 查看log確認(rèn)一下
$ git log
commit 0e149c39eb4401647a9468eaf2b68b45832dbcb2 (HEAD -> master)
Author: kubernete <357018097@qq.com>
Date: Thu Aug 15 22:05:07 2019 +0800
取消tab菜單的360度翻轉(zhuǎn)動(dòng)畫(huà)效果
commit 7c4b1492616ae788e9f58461c72fc12f6c9b1e2d
Author: lijw <357018097@qq.com>
Date: Thu Aug 15 19:44:24 2019 +0800
編寫(xiě)設(shè)備機(jī)組列表中查詢隱藏域填充顯示table行數(shù)
強(qiáng)制將本地代碼推送至遠(yuǎn)程倉(cāng)庫(kù)
但是到了這里,其實(shí)只是本地回退了版本而已,遠(yuǎn)程倉(cāng)庫(kù)的并沒(méi)有回退。如果想要將本地的代碼直接push到遠(yuǎn)程倉(cāng)庫(kù)則會(huì)報(bào)錯(cuò)如下:
$ git push
To gitee.com:kubernete/Performance-Test-Management-demo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@gitee.com:kubernete/Performance-Test-Management-demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
這里會(huì)提示需要更新遠(yuǎn)程倉(cāng)庫(kù),如果更新執(zhí)行git pull的話,又會(huì)將剛才回退的版本下載回來(lái)。
此時(shí)需要強(qiáng)制將本地代碼推送至遠(yuǎn)程倉(cāng)庫(kù)之中,使用git push -f origin master
執(zhí)行如下:
$ git push -f origin master
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered By Gitee.com
To gitee.com:kubernete/Performance-Test-Management-demo.git
+ 6fecbc4...0e149c3 master -> master (forced update)
