問題現象:在分支A上修改后,沒有提交。切換到分支B,發現分支B的內容也修改了。
原因:如果當前分支所做的修改沒有提交的話去其他分支也會看到相同的修改
解決辦法:
1. 用 git add和 git commit提交修改,只要用 git status 檢查工作區和暫存區是干凈的就可以了。
2. 那如果我當前分支上的工作還沒做完,不能提交,但又想去其他分支,這時候可以把當前分支的工作現場隱藏起來。
用 git stash隱藏當前工作現場,這個時候用 git status 查看工作區是干凈的,所以就可以放心地去其他分支了。
用 git stash list可以查看隱藏起來的工作現場
恢復工作現場的兩種方法:
1.用 git stash apply恢復,但是恢復后,stash 內容並不刪除,需要用 git stash drop來刪除; 2.用 git stash pop,恢復的同時把stash內容也刪了,這時候用 git stash list就看不到任何 stash 內容了
可以多次 stash ,恢復的時候,先用 git stash list查看,然后用 git stash apply stash@{0}或者 git stash pop stash@{0}恢復指定的stash
文章轉載自:https://blog.csdn.net/qq_37140632/article/details/85786089
