1. 程式人生 > >Git之checkout到別的分支提示Your local changes to the following files would be overwritten by checkout:

Git之checkout到別的分支提示Your local changes to the following files would be overwritten by checkout:

1 問題

在我自己的分支,然後切換到主分支,提示錯誤如下

Your local changes to the following files would be overwritten by checkout:
 ****file
 ****file

2 解決辦法

先把這些檔案進行add操作,然後再進行commit,就可以了,

git add file

git commit -m 'commit message'

然後你就可以切換分支了,如果你後面再需要切換到這個分支來了之後,因為你已經git commit了,如果檔案是你不想要的,你可以還原git commit操作,命令如下

git reset HEAD~

如果你想了解更多的撤銷git add或則commit或修改了原始檔進行還原操作,請參考我的這篇部落格