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

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

git stash用法

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

$ 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来恢复之前暂存的内容。

$ 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")
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值