git 回滾操作


自己寫了代碼想要回滾,之前自己的方法太耽誤時間了,同事教了一個方法可以快速回滾

 

第一部分:回滾:點擊history-->Version Control-->log

同時選中兩個版本-->

 

2、然后回滾;

 

 

 第二部分提交區

git 有四個區域,1、編輯區,2、暫存區 3、待提交區 4、提交區

1、git status 看一下當前的狀態:

mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git status
位於分支 feature/20210119_8832954_fixed_guid_1
您的分支與上游分支 'origin/feature/20210119_8832954_fixed_guid_1' 一致。

尚未暫存以備提交的變更:
  (使用 "git add <文件>..." 更新要提交的內容)
  (使用 "git restore <文件>..." 丟棄工作區的改動)
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/BizMzEventChannelService.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/impl/BizMzEventChannelServiceImpl.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/price/serivce/impl/BizMzPriceServiceImpl.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizMzPriceServiceMockTest.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizPriceServiceTest.java

未跟蹤的文件:
  (使用 "git add <文件>..." 以包含要提交的內容)
        pms/pms-web/application.pid
        pms/pms-web/bdbtmp/
        pms/pms-web/src/test/java/cn/damai/mz/pms/test/utils/test.java

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

  然后 輸入 2、git add. (注意后面有個點.)

將編輯器放到暫存區

   3、git status  發現很多的新的文件,不需要提交的,直刪除

 

 4、刪除完了在執行:git add.

git status;

 

 5、

git commit -m 'rollback'  (這里-m中間沒有空格)

這是將文件從暫存區到待提交區;

git status

 

 

 6、push  到服務端:

git push

 

 

最后面有如何回滾的代碼示例

 mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git status
位於分支 feature/20210119_8832954_fixed_guid_1
您的分支與上游分支 'origin/feature/20210119_8832954_fixed_guid_1' 一致。

尚未暫存以備提交的變更:
  (使用 "git add <文件>..." 更新要提交的內容)
  (使用 "git restore <文件>..." 丟棄工作區的改動)
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/BizMzEventChannelService.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/impl/BizMzEventChannelServiceImpl.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/price/serivce/impl/BizMzPriceServiceImpl.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizMzPriceServiceMockTest.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizPriceServiceTest.java

未跟蹤的文件:
  (使用 "git add <文件>..." 以包含要提交的內容)
        pms/pms-web/application.pid
        pms/pms-web/bdbtmp/
        pms/pms-web/src/test/java/cn/damai/mz/pms/test/utils/test.java

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git add .
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git status
位於分支 feature/20210119_8832954_fixed_guid_1
您的分支與上游分支 'origin/feature/20210119_8832954_fixed_guid_1' 一致。

要提交的變更:
  (使用 "git restore --staged <文件>..." 以取消暫存)
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/BizMzEventChannelService.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/impl/BizMzEventChannelServiceImpl.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/price/serivce/impl/BizMzPriceServiceImpl.java
        新文件:   pms/pms-web/application.pid
        新文件:   pms/pms-web/bdbtmp/1604062647928158508617requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1604062647928158508617requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1604062647928158508617requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1604062647928158508617requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1604065267957-471726803requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1604065267957-471726803requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1604065267957-471726803requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1604065267957-471726803requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/16040686174281834278468requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/16040686174281834278468requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/16040686174281834278468requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/16040686174281834278468requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/16040698665182142304853requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/16040698665182142304853requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/16040698665182142304853requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/16040698665182142304853requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1604071818154-350741446requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1604071818154-350741446requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1604071818154-350741446requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1604071818154-350741446requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1604305295482-174376996requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1604305295482-174376996requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1604305295482-174376996requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1604305295482-174376996requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1604308919788-1448182593requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1604308919788-1448182593requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1604308919788-1448182593requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1604308919788-1448182593requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/16053431819122037275241requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/16053431819122037275241requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/16053431819122037275241requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/16053431819122037275241requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1611127117468239558394requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1611127117468239558394requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1611127117468239558394requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1611127117468239558394requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1611334641441-736123599requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1611334641441-736123599requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1611334641441-736123599requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1611334641441-736123599requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/16113378282451044529009requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/16113378282451044529009requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/16113378282451044529009requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/16113378282451044529009requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/16119393700161679330568requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/16119393700161679330568requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/16119393700161679330568requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/16119393700161679330568requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1611939781405-1622434999requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1611939781405-1622434999requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1611939781405-1622434999requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1611939781405-1622434999requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1612529149476690762145requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1612529149476690762145requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1612529149476690762145requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1612529149476690762145requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/16126628015651448867886requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/16126628015651448867886requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/16126628015651448867886requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/16126628015651448867886requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1612711390139556174832requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1612711390139556174832requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1612711390139556174832requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1612711390139556174832requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1612712575639-1766288397requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1612712575639-1766288397requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1612712575639-1766288397requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1612712575639-1766288397requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1612713286160147529912requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1612713286160147529912requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1612713286160147529912requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1612713286160147529912requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1612714109267-2075710943requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1612714109267-2075710943requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1612714109267-2075710943requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1612714109267-2075710943requestID.1/je.lck
        新文件:   pms/pms-web/bdbtmp/1612717830671191294880requestID.1/00000000.jdb
        新文件:   pms/pms-web/bdbtmp/1612717830671191294880requestID.1/je.info.0
        新文件:   pms/pms-web/bdbtmp/1612717830671191294880requestID.1/je.info.0.lck
        新文件:   pms/pms-web/bdbtmp/1612717830671191294880requestID.1/je.lck
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizMzPriceServiceMockTest.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizPriceServiceTest.java
        新文件:   pms/pms-web/src/test/java/cn/damai/mz/pms/test/utils/test.java

➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git add . 
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git status
位於分支 feature/20210119_8832954_fixed_guid_1
您的分支與上游分支 'origin/feature/20210119_8832954_fixed_guid_1' 一致。

要提交的變更:
  (使用 "git restore --staged <文件>..." 以取消暫存)
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/BizMzEventChannelService.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/impl/BizMzEventChannelServiceImpl.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/price/serivce/impl/BizMzPriceServiceImpl.java
        新文件:   pms/pms-web/application.pid
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizMzPriceServiceMockTest.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizPriceServiceTest.java
        新文件:   pms/pms-web/src/test/java/cn/damai/mz/pms/test/utils/test.java

➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git add . 
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git status
位於分支 feature/20210119_8832954_fixed_guid_1
您的分支與上游分支 'origin/feature/20210119_8832954_fixed_guid_1' 一致。

要提交的變更:
  (使用 "git restore --staged <文件>..." 以取消暫存)
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/BizMzEventChannelService.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/eventchannel/service/impl/BizMzEventChannelServiceImpl.java
        修改:     pms/pms-biz/src/main/java/cn/damai/mz/pms/biz/price/serivce/impl/BizMzPriceServiceImpl.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizMzPriceServiceMockTest.java
        修改:     pms/pms-web/src/test/java/cn/damai/mz/pms/test/service/price/BizPriceServiceTest.java
        新文件:   pms/pms-web/src/test/java/cn/damai/mz/pms/test/utils/test.java

➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) ✗ git commit -m 'rollback'
[feature/20210119_8832954_fixed_guid_1 3c6a37452] rollback
 6 files changed, 100 insertions(+), 187 deletions(-)
 create mode 100644 pms/pms-web/src/test/java/cn/damai/mz/pms/test/utils/test.java
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) git status
位於分支 feature/20210119_8832954_fixed_guid_1
您的分支領先 'origin/feature/20210119_8832954_fixed_guid_1' 共 1 個提交。
  (使用 "git push" 來發布您的本地提交)

無文件要提交,干凈的工作區
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) git status
位於分支 feature/20210119_8832954_fixed_guid_1
您的分支領先 'origin/feature/20210119_8832954_fixed_guid_1' 共 1 個提交。
  (使用 "git push" 來發布您的本地提交)

無文件要提交,干凈的工作區
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) git push
枚舉對象: 67, 完成.
對象計數中: 100% (67/67), 完成.
使用 8 個線程進行壓縮
壓縮對象中: 100% (25/25), 完成.
寫入對象中: 100% (36/36), 12.95 KiB | 4.32 MiB/s, 完成.
總共 36 (差異 13),復用 6 (差異 0)
To http://gitlab.alibaba-inc.com/damai-mz/mz-pms.git
   152f05efa..3c6a37452  feature/20210119_8832954_fixed_guid_1 -> feature/20210119_8832954_fixed_guid_1
➜  mz-pms git:(feature/20210119_8832954_fixed_guid_1) 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM