码迷,mamicode.com
首页 > 其他好文 > 详细

Git 藏匿操作

时间:2016-11-02 01:24:40      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:pos   目录   ted   commit   切换   key   size   tag   har   

假设您正在为您的产品实施的一项新功能。你的代码是在推进开发进度而客户不断升级需求突然来了。正因为如此,你必须保持放下你的新功能,工作几个小时。你不能提交你的部分代码,也不能扔掉你的变化。所以,你需要一些临时空间,在那里你可以存储你的部分修改,以便以后再提交。

在Git中,藏匿操作需要修改的跟踪文件和阶段的变化,并将其保存在栈上未完成的更改,可以在任何时候重新。

[jerry@CentOS project]$ git status -s M string.c ?? string

现在要切换分支机构为客户不断升级,但你不想提交你的工作,所以你会藏匿的变化。要推一个新的藏匿到您的堆栈,运行git stash命令

[jerry@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命令验证。

[jerry@CentOS project]$ git status -s ?? string

现在可以安全地切换分支和做其他工作。我们可以看到的藏匿的变化列表通过使用 git stash list 命令。

[jerry@CentOS project]$ git stash list stash@{0}: WIP on master: e86f062 Added my_strcpy function

假设你解决了客户不断升级和你要回到你的工作,已经做了一半的代码。只要执行git stash pop 命令,它会从堆栈中删除的变化,并把它放在当前工作目录。

[jerry@CentOS project]$ git status -s ?? string

[jerry@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) [jerry@CentOS project]$ git status -s M string.c ?? string

PS:如果您想和业内技术大牛交流的话,请加qq群(521249302)或者关注微信公众 号(AskHarries),谢谢!

Git 藏匿操作

标签:pos   目录   ted   commit   切换   key   size   tag   har   

原文地址:http://www.cnblogs.com/kluan/p/6021362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!