如何通过Android Studio从Git运行特定版本的应用程序?



我使用git作为我的VCS,每隔几天提交我的代码。然而,一个bug已经悄悄进来,我需要检查之前提交的应用程序版本是否也有这个bug。

我如何保持切换当前代码库到不同的git版本而不丢失我没有提交的本地更改?在Android Studio中是否有一种方法可以直接从git构建和测试特定版本?

有人可能认为是git stashgit stash pop/apply

git stash
git checkout <commit>
# build and test
git checkout <previous-branch>
git stash pop
# or git stash apply

但我推荐git worktree。假设版本为abc123:

git worktree add /path/to/foo abc123
cd /path/to/foo
# build and test

abc123的文件夹和文件检出到/path/to/foo。它不会影响当前的主工作树。当任务在/path/to/foo中完成时,您可以通过以下方式删除额外的工作树:

git worktree remove /path/to/foo
# or
rm -rf /path/to/foo
git worktree prune

最新更新