美文网首页程序员
关于git stash命令

关于git stash命令

作者: aurora | 来源:发表于2014-03-06 20:18 被阅读215次

今天完成了一个新功能准备提交到服务器的git仓库上,发现有同事更新了项目,但是我的本地git仓库的项目代码不是最新版本,为了避免出现版本冲突,所以Google了一下解决方案,见文末的参考资料
主要是用到了git stash命令,此命令的应用场景是:本地代码发生了改动,但是不想提交到代码仓库里,于是把这部分改动暂存起来。
于是我执行了

$ git stash
Saved working directory and index state "WIP on master: 049d078 added the index file" HEAD is now at 049d078 added the index file (To restore them type "git stash apply")

这时本地项目恢复到了改动之前的版本,执行

$ git pull
Merge made by the 'recursive' strategy. ...... 11 files changed, 249 insertions(+), 281 deletions(-)

合并了服务器上最新的改动,接着执行

$ git stash pop
...... Dropped refs/stash@{0} (....)

暂存的内容恢复并在堆栈中删除它。如果你不想删除,就不要执行git stash pop命令,而执行git stash apply命令。此时你可以使用git diff -w +文件名来确认代码自动合并的情况,然后查看git status,该git addgit commitgit push就执行吧。

参考资料

  1. Git:代码冲突常见解决方法
  2. 关于git pull的问题,如何在不commit的前提下pull回来?

相关文章

  • stash 操作暂存区

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

  • git stash

    git stash 或者git stash save (两种命令相同,save可以添加注释) git stash ...

  • git stash 用法总结和注意点

    常用git stash命令: (1)git stash save "save message" : 执行存储时,...

  • 常用git stash命令

    常用git stash命令: (1)git stash save "save message" : 执行存储时,...

  • 2021-08-16 git stash 用法总结和注意点

    常用git stash命令: (1)git stash save "save message" : 执行存储时,...

  • git stash常用命令

    常用git stash命令: (1)git stash save "save message" : 执行存储时,...

  • git stash

    常用git stash命令: (1)git stash save "save message" : 执行存储时,...

  • git stash 相关命令

    常用git stash命令: git stash save "save message" : 执行存储时,添加备...

  • 关于git stash命令

    今天完成了一个新功能准备提交到服务器的git仓库上,发现有同事更新了项目,但是我的本地git仓库的项目代码不是最新...

  • git-stash的使用

    一、命令: git stash [save] 保存脏状态,恢复修改前状态 git stash pop 提取脏状态 ...

网友评论

    本文标题:关于git stash命令

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