需要一边修线上分支,一边继续做新功能时,我一般会用 git worktree,不用反复 stash:
git worktree add ../app-hotfix hotfix
git worktree add ../app-feature -b feature/login
git worktree list
这样两个目录共用同一个 Git 对象库,但各自有工作区和当前分支。改完后可以这样清理:
git worktree remove ../app-hotfix
环境:Git 2.x,Linux、macOS、Windows 都能用。注意同一个分支不能同时被两个 worktree 检出;删除目录前最好用 git worktree remove,让 Git 同步清理记录。