git stash简单介绍

git stash简单介绍

如果你此时在开发一个功能,预计需要1-2天开发完,老大突然跟你说有一个紧急bug需要修复,你不想commit当前代码破坏当前工作,那么这时候该怎么办呢?

这里就推荐一个git很不错的功能,git stash功能,暂存你当前的代码,方便你当前去完成其他要紧工作

主要命令

//暂存当前工作
git stash
//查看暂存列表
git stash list
//恢复最近一次暂存
git stash pop

使用介绍

你这里已经修改了一部分代码,需要紧急去修复一个bug

//查看当前修改状态
git status

On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   visitMyBlog.py

no changes added to commit (use "git add" and/or "git commit -a")
feiqianyousadeMacBook-Pro:forgeVisitMyblog yousa$

//暂存当前工作
git stash

//切换到工作分支完成工作
git checkout xxx
或者
git branch xxx

待修改完成后,切回自己的分支,查看查看暂存状态

//查看已经暂存的代码
git stash list

stash@{0}: WIP on master: 65f7e54 change user_agent

//恢复最近一次暂存
git stash pop

//这样就恢复了之前暂存的工作状态
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   visitMyBlog.py

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (9ab02b46d95341069d8c31f71035d014eb6f0483)

这时候使用git status你就会发现之前的修改又恢复了,又可以继续愉快的开发了!:D

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值