git 復原錯誤的pull origin操作

來源:互聯網
上載者:User

git remote show origin   其中的origin表示自己的項目根目錄了。

$ git remote show origin* remote origin  Fetch URL: git@gitlab.alibaba-inc.com:middleware/jingwei.git  Push  URL: git@gitlab.alibaba-inc.com:middleware/jingwei.git  HEAD branch: master  Remote branches:    br-2.1.2.1 tracked    br-2.1.2.2 tracked    br-2.1.3   tracked    master     tracked  Local branches configured for 'git pull':    br-2.1.2.2 merges with remote br-2.1.2.2    master     merges with remote master  Local refs configured for 'git push':    br-2.1.2.2 pushes to br-2.1.2.2 (local out of date)    master     pushes to master     (up to date)shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)$ git remote showorigin

2 把遠程分支 br-2.1.2.1 pull下來,發現把當前分支給覆蓋了,想復原到之前的修改

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master);當前分支是master,其實想把br-2.1.2.1的代碼抓到本地,執行 git pull 相當於 git fetch 和 git merge兩個操作的效果,把遠端br-2.1.2.1抓達到本地,並和目前的版本合并。(這樣做有沒有把br-2.1.2.1抓下來呢?)

$ git pull origin br-2.1.2.1From gitlab.alibaba-inc.com:middleware/jingwei * branch            br-2.1.2.1 -> FETCH_HEADAuto-merging pom.xmlCONFLICT (content): Merge conflict in pom.xmlAuto-merging jingwei-webconsole/pom.xmlCONFLICT (content): Merge conflict in jingwei-webconsole/pom.xmlAuto-merging jingwei-monitor/pom.xmlCONFLICT (content): Merge conflict in jingwei-monitor/pom.xmlAuto-merging jingwei-core/src/main/java/com/taobao/jingwei/core/kernel/AbstractJingWeiCore.javaCONFLICT (content): Merge conflict in jingwei-core/src/main/java/com/taobao/jingwei/core/kernel/AbstractJingWeiCore.javaAuto-merging jingwei-core/pom.xmlAutomatic merge failed; fix conflicts and then commit the result.

執行完pull origin後,發現想要抓的版本並沒有抓下來

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)$ git pull origin br-2.1.2.1From gitlab.alibaba-inc.com:middleware/jingwei * branch            br-2.1.2.1 -> FETCH_HEADAuto-merging pom.xmlCONFLICT (content): Merge conflict in pom.xmlAuto-merging jingwei-webconsole/pom.xmlCONFLICT (content): Merge conflict in jingwei-webconsole/pom.xmlAuto-merging jingwei-monitor/pom.xmlCONFLICT (content): Merge conflict in jingwei-monitor/pom.xmlAuto-merging jingwei-core/src/main/java/com/taobao/jingwei/core/kernel/AbstractJingWeiCore.javaCONFLICT (content): Merge conflict in jingwei-core/src/main/java/com/taobao/jingwei/core/kernel/AbstractJingWeiCore.javaAuto-merging jingwei-core/pom.xmlAutomatic merge failed; fix conflicts and then commit the result.shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master|MERGING)$ git br  br-2.1.2.2* master

(1)使用 git reset --hard HEAD 命令撤銷這次 pull origin 操作 ,還原到最近一次修改

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master|MERGING)$ git reset --hard HEADHEAD is now at 89700a3 optimize upload fileshuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)$ git status# On branch masternothing to commit, working directory clean

(2)使用 git reset --hard HEAD^

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master|MERGING)$ git reset --hard HEAD^HEAD is now at f6423ad modify groupshuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)$ git status# On branch master# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.#nothing to commit, working directory clean

再pull一下

$ git pullUpdating f6423ad..89700a3Fast-forward .../webconsole/biz/exception/TimeoutException.java | 29 +++++++++ .../webconsole/util/upload/UploadFileImpl.java     | 46 ++++++++++++++ .../webconsole/util/upload/UploadFileService.java  | 19 ++++-- .../web/filter/JingweiSecurityFilter.java          | 74 +++++++++++++++------- .../webconsole/web/filter/UploadFileFilter.java    | 29 +++++++++ .../web/module/screen/api/JingweiGateWay.java      |  8 ++- .../screen/api/cmd/GetConsoleTarTimeCommand.java   | 61 ++++++++++++++++++ 7 files changed, 238 insertions(+), 28 deletions(-) create mode 100644 jingwei-webconsole/src/main/java/com/taobao/jingwei/webconsole/biz/exception/TimeoutException.java create mode 100644 jingwei-webconsole/src/main/java/com/taobao/jingwei/webconsole/web/module/screen/api/cmd/GetConsoleTarTimeCommand.javashuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (master)$ git status# On branch masternothing to commit, working directory clean

看下git log,發現 “modify group“這次修改早於 ”optimize upload file“這次修改。說明HEAD表示最近一次提交的修改,HEAD^表是最近second新的提交的修改。

前面的7為數字正好一大串數位前7位。

commit 89700a31c005001d34256761dd4c945c6c70a06
commit f6423ad5ca231e00e44626a2dcb8ba300c7a5fe
Updating f6423ad..89700a3

Updating表示本地工作目錄從 一個版本(f6423ad)變更到另一個版本(89700a3)。

$ git logcommit 89700a31c005001d34256761dd4c945c6c70a06Author: shuohai.lhl <shuohai.lhl@taobao.com>Date:   Sat Aug 3 19:54:46 2013 +0800    optimize upload filecommit f6423ad5ca231e00e44626a2dcb8ba300c7a5feAuthor: shuohai.lhl <shuohai.lhl@taobao.com>Date:   Mon Jul 29 10:42:37 2013 +0800    modify groupcommit aa4ae6f4f447471d15038b73cb4d5c52b2eb623Author: shuohai.lhl <shuohai.lhl@taobao.com>Date:   Fri Jul 26 10:25:06 2013 +0800    revertcommit ba1b6e5e997e866f013cda0feaa043115623d7fAuthor: shuohai.lhl <shuohai.lhl@taobao.com>Date:   Fri Jul 26 09:05:37 2013 +0800    rightcommit ceec1780e44570e6c311ec7d1db86a0f17e268cAuthor: shuohai.lhl <shuohai.lhl@taobao.com>Date:   Fri Jul 26 09:00:29 2013 +0800    rightcommit 2f4ce1c1d31be5ffa1d2e79baa98979c36ae99cAuthor: shuohai.lhl <shuohai.lhl@taobao.com>Date:   Sun Jul 21 18:26:12 2013 +0800    fix zk config must match stat config.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.