企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
假设您正在为您的产品实施的一项新功能。你的代码是在推进开发进度而客户不断升级需求突然来了。正因为如此,你必须保持放下你的新功能,工作几个小时。你不能提交你的部分代码,也不能扔掉你的变化。所以,你需要一些临时空间,在那里你可以存储你的部分修改,以便以后再提交。 在Git中,藏匿操作需要修改的跟踪文件和阶段的变化,并将其保存在栈上未完成的更改,可以在任何时候重新。 [byron@CentOS project]$ git status -s M string.c ?? string 现在要切换分支机构为客户不断升级,但你不想提交你的工作,所以你会藏匿的变化。要推一个新的藏匿到您的堆栈,运行git stash命令 [byron@CentOS project]$ git stash Saved working directory and index state WIP on master: e86f062 Added my_strcpy function HEAD is now at e86f062 Added my_strcpy function 现在你的工作目录是干净的,所有的改变都保存在堆栈。让我们用git status命令验证。 [byron@CentOS project]$ git status -s ?? string 现在可以安全地切换分支和做其他工作。我们可以看到的藏匿的变化列表通过使用 git stash list 命令。 [byron@CentOS project]$ git stash list stash@{0}: WIP on master: e86f062 Added my_strcpy function 假设你解决了客户不断升级和你要回到你的工作,已经做了一半的代码。只要执行git stash pop 命令,它会从堆栈中删除的变化,并把它放在当前工作目录。 [byron@CentOS project]$ git status -s ?? string [byron@CentOS project]$ git stash pop 上面的命令会产生以下结果。 # On branch master # Changed but not updated: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: string.c # # Untracked files: # (use "git add ..." to include in what will be committed) # # string no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (36f79dfedae4ac20e2e8558830154bd6315e72d4) [byron@CentOS project]$ git status -s M string.c ?? string