首頁 > 軟體

Git實現克隆歷史的某個版本

2022-09-26 14:05:27

步驟

檢視歷史記錄

# 檢視歷史記錄git log -3

範例

Simba@SIMBA MINGW64 /t/IDE/IDEA/Workspace-Learn/config-center ((af05c43...))
$ git log -3
commit af05c43b5c6b14abbe9c6267811e4fb0a2d2b372 (HEAD, origin/master, origin/HEAD, master)
Author: Simba1949 <simba1949@outlook.com>
Date:   Sun Jul 28 17:27:54 2019 +0800
    springcloud多環境組態檔
commit d124e2b35da7a9b51368e5f2d156b1128781c517
Author: Simba1949 <simba1949@outlook.com>
Date:   Sun Jul 28 16:39:14 2019 +0800
    SpringCloudConfig 多環境組態檔
commit acb80687cd82151f1beba3518c6a5327fad91c9a
Author: Simba1949 <simba1949@outlook.com>
Date:   Sun Jul 28 11:40:10 2019 +0800
    SpringCloud 學習筆記之分散式設定中心Config的學習,上傳組態檔

選擇要克隆的歷史版本,克隆對應的歷史版本資料

# 選擇需要克隆的歷史版本
git checkout acb80687cd82151f1beba3518c6a5327fad91c9a

範例

Simba@SIMBA MINGW64 /t/IDE/IDEA/Workspace-Learn/config-center ((af05c43...))
$ git checkout acb80687cd82151f1beba3518c6a5327fad91c9a
Previous HEAD position was af05c43 springcloud多環境組態檔
HEAD is now at acb8068 SpringCloud 學習筆記之分散式設定中心Config的學習,上傳組態檔

最後在恢復到最新資料

# 恢復最新資料
git pull origin master

範例

Simba@SIMBA MINGW64 /t/IDE/IDEA/Workspace-Learn/config-center ((acb8068...))
$ git pull origin master
From https://github.com/simba1949/config-center
 * branch            master     -> FETCH_HEAD
Updating acb8068..af05c43
Fast-forward
 .../default/spring-cloud-config-multi-client.properties                  | 1 +
 .../dev/spring-cloud-config-multi-client-dev.properties                  | 1 +
 .../prod/spring-cloud-config-multi-client-prod.properties                | 1 +
 .../spring-cloud-config-multi-client-dev.properties                      | 1 +
 .../spring-cloud-config-multi-client-prod.properties                     | 1 +
 .../spring-cloud-config-multi-client-test.properties                     | 1 +
 .../test/spring-cloud-config-multi-client-test.properties                | 1 +
 7 files changed, 7 insertions(+)
 create mode 100644 spring-cloud-config-multi-client/default/spring-cloud-config-multi-client.properties
 create mode 100644 spring-cloud-config-multi-client/dev/spring-cloud-config-multi-client-dev.properties
 create mode 100644 spring-cloud-config-multi-client/prod/spring-cloud-config-multi-client-prod.properties
 create mode 100644 spring-cloud-config-multi-client/spring-cloud-config-multi-client-dev.properties
 create mode 100644 spring-cloud-config-multi-client/spring-cloud-config-multi-client-prod.properties
 create mode 100644 spring-cloud-config-multi-client/spring-cloud-config-multi-client-test.properties
 create mode 100644 spring-cloud-config-multi-client/test/spring-cloud-config-multi-client-test.properties
Simba@SIMBA MINGW64 /t/IDE/IDEA/Workspace-Learn/config-center ((af05c43...))

演示

Git 最新版本資料

克隆歷史版本後

最終恢復到最新版本資料

命令演示

以上為個人經驗,希望能給大家一個參考,也希望大家多多支援it145.com。


IT145.com E-mail:sddin#qq.com