前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >GIT-缓存本地不想提交的代码

GIT-缓存本地不想提交的代码

作者头像
用户2475223
发布2019-12-17 15:57:30
2K0
发布2019-12-17 15:57:30
举报
文章被收录于专栏:codersamcodersam

开发的过程中,有时之前开发的功能出现了BUG,但是本地又在相同的文件中开发了新的需求时,需要将代码还原再修复BUG。可是代码还原的话大大提高了二次开发的成本。 通过git help -a 获取全部的git命令可以看到git stash这个命令。

git stash用法

git stash是将本地当前未提交的内容暂存起来并且将修改的文件还原到修改之前的状态,用于后续恢复当前的工作,不会被git push到远程分支。

代码语言:javascript
复制
$ git status
On branch branch
Your branch is up to date with 'origin/branch'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   path/filename
$ git stash
Saved working directory and index state WIP on branch: commitId commitMessage
$ git status
On branch branch
Your branch is up to date with 'origin/branch'.
nothing to commit, working tree clean

这样我们就可以在不还原新的开发的情况下去处理已知的BUG了。

git stash pop删除暂存并恢复暂存的内容

使用git stash pop来恢复之前暂存的内容。

代码语言:javascript
复制
$ git stash pop
On branch branch
Your branch is up to date with 'origin/branch'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   path/filename

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (abcb5f4acecedb44a92ff1b6c94542b503af4a01)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年5月28日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • git stash用法
  • git stash pop删除暂存并恢复暂存的内容
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档