使用场景
当在当前的分支已开发到一半,需要切换到别的分支修改代码时,为了不造成log上有不必要的记录,就可以使用git stash将当前未提交的代码推入到git栈中,等到修改完成后,再切换回来,使用git stash pop将以前写了一半的代码恢复回来就好了
基本用法
将当前的更改保存到git栈中
git stash
将当前的更改保存到git栈中,并添加备注信息
git stash save ‘备注信息’
将当前的更改保存到git栈中,包括新增的文件
git stash -u
将git栈中的第一个stash恢复到当前,并删除git栈中的第一个stash
git stash pop
查看git栈中保存的所有更改
git stash list
将git栈中指定的第几个更改恢复到当前工作区
git stash apply stash@{num
}
注:在vscode终端使用时需要加反引号,否则会报错
eg:git stash apply stash@`{1`}
删除git栈中指定的第几个更改
git stash drop stash@{num}
误删了git栈中的更改,可以使用以下这个命令查找所有的更改
git fsck --lost-found >> practiceDemo.vue
查看某个哈希值为一下的blob对象的内容
git show 61863e5f389c457c37a376f8a7906d6484cb9754 > recovered_file.txt
将git栈中指定的id的更改恢复到当前工作区
git stash apply 详细的id