美文网首页
Git stash的用法

Git stash的用法

作者: sugarkawhi | 来源:发表于2016-06-28 15:07 被阅读158次

在开发完成一个版本后,我们会提交一分干净的代码到分支上,然后新建一个分支,去开发新的功能。

但是,天有不测风云,在新功能做了一部分的时候,还没开发完成,Boss告知,上一个版本有个问题,需要修改。此时,新功能还未开发完成,不想提交。那怎么办?

此时,我们可以使用Git stash命令,命令简介:git stash

git stash
命令用来临时地保存一些还没有提交的工作,以便在分支上不需要提交未完成工作就可以清理工作目录。

$ git stash
warning: LF will be replaced by CRLF in app/src/main/java/com/xxx/xxx/
xxx/ConfigInfo.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in app/src/main/res/layout/item_index_ad.xml.
The file will have its original line endings in your working directory.
Saved working directory and index state WIP on zzy/feature/issue-8: 25d8758 Merg
e pull request #7 from buzzerbeat/zzy/feature/issue-5
HEAD is now at 25d8758 Merge pull request #7 from buzzerbeat/zzy/feature/issue-5

报了两个警告,暂时不用管它。
然后在使用git status命令:

$ git status
On branch zzy/feature/issue-8
Your branch is up-to-date with 'origin/zzy/feature/issue-8'.

nothing to commit, working directory clean

最后一句显示,工作目录是干净的了。此时,我们就可以做一些其他的操作了。

一会后,我们调整完了,需要接着开发新的功能,我们就需要把之前的代码拿出来,之前的代码其实是储藏在栈中了,这时候,需要借助 git stash pop 命令,使代码弹出栈。


$ git stash pop
On branch zzy/feature/issue-8
Your branch is up-to-date with 'origin/zzy/feature/issue-8'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   app/libs/GDTUnionSDK.4.8.527.min.jar
        new file:   app/src/main/res/layout/item_index_ad.xml

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:   app/build.gradle
        modified:   app/src/main/AndroidManifest.xml
        ...//这里省略,因为我修改了很多。

这样,我们又可以接着新功能愉快的开发了。
以上。

附:Git 工具 - 储藏与清理 这里讲的相当完善,不仅仅只这一个方面。
学习更多git使用,戳这里!

相关文章

  • [ Git ] 快速参考

    配置 常用的用户信息配置 常用的别名配置 git rm 的用法 git reset 的用法 git stash 的...

  • Git stash 技巧

    Git stash常用技巧 git stash save git stash list git stash app...

  • stash 操作暂存区

    涉及命令:git stash、stash list、git stash apply、git stash drop ...

  • Git Stash用法

    Git Stash用法 最近在使用Git管理项目工程的时候,遇到了很多问题,也学习到了很多关于Git常见使用的技巧...

  • git stash用法

    每天都重复着一样的步骤,今天也是一样,打开电脑,先看git上面有没有代码更新,于是先pull代码,pull完了之后...

  • git stash用法

    git stash list 看有哪些git stash show stash@{0} 看某一个stash有哪些文...

  • git stash用法

    一、应用场景 1、 当正在dev分支上开发某个项目,这时项目中出现一个bug,需要紧急修复,但是正在开发的内容只是...

  • git stash 用法

    一、常用git stash命令: 1、git stash 能够将所有未提交的修改(工作区和暂存区)保存至堆栈中,用...

  • Git_stash

    git stash 用法 git stash用于将当前工作区的修改暂存起来,就像堆栈一样,可以随时将某一次缓存的修...

  • 【Git】stash

    stash git stash // 加入缓存区git stash save "注释"git stash list...

网友评论

      本文标题:Git stash的用法

      本文链接:https://www.haomeiwen.com/subject/btetjttx.html