git stash 用法

git stash 是一个用于临时保存("stashing")工作目录中的修改的 Git 命令。这在需要临时切换到其他分支,但不想提交当前工作的修改时非常有用。

基础用法

  • 保存修改: 使用 git stashgit stash save 将暂存区和工作目录中的修改保存到一个新的储藏。

    复制代码
    git stash
  • 查看储藏列表: 使用 git stash list 查看所有的储藏。

    复制代码
    git stash list
  • 应用储藏: 使用 git stash apply 应用最近的储藏。

    复制代码
    git stash apply

    对于特定的储藏,使用:

    复制代码
    git stash apply stash@{n}
  • 删除储藏: 使用 git stash drop 删除最近的储藏。

    复制代码
    git stash drop

    对于特定的储藏,使用:

    复制代码
    git stash drop stash@{n}
  • 弹出储藏: 使用 git stash pop 应用最近的储藏,并删除它。

    复制代码
    git stash pop

高级用法

  • 保存未跟踪的文件: 使用 git stash -ugit stash --include-untracked 将未跟踪的文件也保存在储藏中。

    复制代码
    git stash -u
  • 应用并保留储藏: 默认情况下,git stash apply 会保留储藏。但如果你想在应用之后立即删除它,可以使用 git stash pop

  • 命名储藏: 你也可以给储藏一个描述性的名字。

    复制代码
    git stash save "Your stash message here"

这只是 git stash 的一些基本和高级用法,但它提供了一种灵活的方式来管理工作目录的修改。

相关推荐
Zach_yuan2 小时前
版本控制器Git
linux·git
唐青枫7 小时前
Git 提交时神秘的 create mode 100644 到底是什么?一文告诉你答案!
git
春生野草7 小时前
Git-git stash与分支管理
git
ljh5746491197 小时前
Git合并冲突解决方法
git
悟能不能悟7 小时前
git revert commit和undo commit的区别
git
222you19 小时前
Git的diff命令
git
补三补四21 小时前
Git 基础操作指南
大数据·git·elasticsearch
222you1 天前
git的命令
git
Coolbike1 天前
Git工作流
git
~央千澈~1 天前
实战针对本地项目git如何移除旧仓库关联并且添加关联新仓库-优雅草卓伊凡
git