0
点赞
收藏
分享

微信扫一扫

git stash详解

我阿霆哥 2022-01-26 阅读 78

git stash详解

1. stash工具的应用场景

当本地修改了一批代码,但是需要提交的只是修改中的部分文件或部分代码,可以将不需要提交的部分存入stash,push完之后pop出来继续开发。

2. stash常用命令

1) git stash

作用:将所有修改的文件添加到stash

$ git status
On branch gxtdev
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:   file1.c
        modified:   file2.c
        modified:   file3.c

no changes added to commit (use "git add" and/or "git commit -a")
$ git stash
Saved working directory and index state WIP on gxtdev: 216a546 Merge branch 'master' into gxtdev

2) git stash list

作用:查看stash列表,列表以节点的形式存在

$ git stash list
stash@{0}: WIP on gxtdev: 216a546 Merge branch 'master' into gxtdev
stash@{1}: WIP on gxtdev: 7cb4301 删除xxxxxx

3) git stash show

作用:查看stash中文件的更改情况(哪个文件有几处修改)

$ git stash show
 file1.c | 2 +-
 file2.c | 2 +-
 file3.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

4) git stash pop

作用:将stash中的文件"弹"出来

$ git stash pop
On branch gxtdev
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:   file1.c
        modified:   file2.c
        modified:   file3.c

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

5) git stash clear

作用:清除stash

$ git stash clear
无提示即clear成功
$ git stash list
无提示即stash中无内容

6) git stash push [file1] [file2] [file3]…

作用:将部分文件添加到stash

该指令非常实用,不像第1条将所有的文件添加到stash,该语句可以自行选择加入stash的文件

7) git stash -p

作用:该指令是一个交互式命令,能够一个文件一个文件的遍历,决定每一个文件的操做方式。y放入stash,n不放入stash

该指令对于文件中的每一处修改都进行操作算则是否加入stash,个人觉得该指令针对同一个文件中同时存在有push和stash的情况比较使用。

举报

相关推荐

0 条评论