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 的一些基本和高级用法,但它提供了一种灵活的方式来管理工作目录的修改。

相关推荐
南境十里·墨染春水13 小时前
linux学习进展 git详解
linux·git·学习
zhangfeng113314 小时前
CodeBuddy ai对话框上面的git docs terminal Rulds 干嘛用的,以thinkphp fastadmin 为例,插件市场
人工智能·git·编程
OYangxf15 小时前
Git Conflict Resolution
大数据·git·elasticsearch
高斯林.神犇15 小时前
Git全套流程
git
次元工程师!17 小时前
LangFlow开发(一)—安装和部署
git·python·大模型·langflow
怣疯knight17 小时前
【无标题】
git
Jim-zf18 小时前
git 锁文件
git
lcx_defender18 小时前
Git常见操作与指令
git
一只积极向上的小咸鱼1 天前
嵌套 Git 仓库 / gitlink / submodule 问题总结
大数据·git·elasticsearch
LuDvei1 天前
git拉取报错问题
git