[Git] 還原Git上commit,但是沒有push代碼

來源:互聯網
上載者:User

標籤:

直接在Idea上操作2步解決:

1. 找到:

 2. 在To Commit裡面填寫:HEAD^,表示將commit的資訊還原為上一次的,需要多次直接reset多次即可:

使用命令列:原理一樣

以下內容轉載:

http://zhyq0826.iteye.com/blog/1671638

如果不小心commit了一個不需要commit的檔案,可以對其進行撤銷。 

先使用git log 查看 commit日誌

commit 422bc088a7d6c5429f1d0760d008d86c505f4abeAuthor: zhyq0826 <[email protected]>Date:   Tue Sep 4 18:19:23 2012 +0800    刪除最近搜尋數目限制commit 8da0fd772c3acabd6e21e85287bdcfcfe8e74c85Merge: 461ac36 0283074Author: zhyq0826 <[email protected]>Date:   Tue Sep 4 18:16:09 2012 +0800

找到需要回退的那次commit的 雜湊值,

git reset --hard commit_id 

 使用上面的命令進行回退

起因: 不小新把記錄了公司伺服器IP,帳號,密碼的檔案提交到了git
方法:
    git reset --hard <commit_id>
    git push origin HEAD --force
其他:
    根據–soft –mixed –hard,會對working tree和index和HEAD進行重設:
    git reset –mixed:此為預設,不帶任何參數的git reset,即時這種方式,它回退到某個版本,只保留源碼,回退commit和index資訊
    git reset –soft:回退到某個版本,只回退了commit的資訊,不會恢複到index file一級。如果還要提交,直接commit即可
    git reset –hard:徹底回退到某個版本,本地的源碼也會變為上一個版本的內容

    HEAD 最近一個提交
    HEAD^ 上一次
    <commit_id> 每次commit的SHA1值. 可以用git log 看到,也可以在頁面上commit標籤頁裡找到

[Git] 還原Git上commit,但是沒有push代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.