標籤:
直接在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代碼