当前分支写了部分代码时,需要切换到另一个分支时,需要保持当前分支工作区干净,即没有修改记录,此时可以git commit后再checkout到另一个分支, 或者git stash暂存代码后切换分支。
1. Stash 暂存
Git -> Uncommitted Changes -> Stash Changes
Message中写上备注,Create Stash后修改的内容就不见了
Commit 工具窗口中 Commit 选项卡旁边的 Stash 选项卡出现暂存记录
2. Unstash 取出
Git -> Uncommitted Changes -> Unstash Changes
选择对应的缓存记录,点击apply或pop即可,apply会保存缓存记录,而点击pop会删去记录
注意:
1. 取出暂存内容时,工作区要保持干净,没有修改记录。
否则会报错:
Your local changes to the following files would be overwritten by merge,
Please commit your changes or stash them before you merge.
2. 右键暂存记录->Unstash可以基于所选存储创建新分支,而不是将其应用于当前签出的分支