今天用git pull更新代碼或者git checkout切換分支時(shí),遇到了一個(gè)的問題:
error: Your local changes to the following files would be overwritten by merge:
package.json
Please commit your changes or stash them before you merge.
Aborting
就是發(fā)生了git沖突,但是我又不想commit我本地的修改,那就只能試試提示中的另一種方法:
- stash
git stash
git pull
git stash pop
git stash: 備份當(dāng)前的工作區(qū)的內(nèi)容,從最近的一次提交中讀取相關(guān)內(nèi)容,讓工作區(qū)保證和上次提交的內(nèi)容一致。同時(shí),將當(dāng)前的工作區(qū)內(nèi)容保存到Git棧中。
git stash pop: 從Git棧中讀取最近一次保存的內(nèi)容,恢復(fù)工作區(qū)的相關(guān)內(nèi)容。由于可能存在多個(gè)Stash的內(nèi)容,所以用棧來管理,pop會(huì)從最近的一個(gè)stash中讀取內(nèi)容并恢復(fù)。
git stash list: 顯示Git棧內(nèi)的所有備份,可以利用這個(gè)列表來決定從那個(gè)地方恢復(fù)。
git stash clear: 清空Git棧。此時(shí)使用gitg等圖形化工具會(huì)發(fā)現(xiàn),原來stash的哪些節(jié)點(diǎn)都消失了。
2.放棄本地的修改,直接覆蓋
git reset
git pull
原文鏈接:https://blog.csdn.net/lincyang/article/details/21519333