1. 程式人生 > >不小心本地git commit了程式碼怎麼辦

不小心本地git commit了程式碼怎麼辦

如果不小心commit了怎麼辦?

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


先使用git log 檢視 commit日誌
commit 422bc088a7d6c5429f1d0760d008d86c505f4abe  
Author: zhyq0826 <[email protected]>  
Date:   Tue Sep 4 18:19:23 2012 +0800  
  
    刪除最近搜尋數目限制  
  
commit 8da0fd772c3acabd6e21e85287bdcfcfe8e74c85  
Merge: 461ac36 0283074  
Author: zhyq0826 <
[email protected]
>   Date:   Tue Sep 4 18:16:09 2012 +0800  

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

git reset --hard commit_id

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

git reset --hard commit_id