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

相关推荐
云攀登者-望正茂2 小时前
将 develop 分支拉取到特性分支时解决合并污染问题
git
金銀銅鐵4 小时前
[git] 如何找到已经“丢失”的 commit?
git·后端
尘世壹俗人5 小时前
linux编译安装git
linux·运维·git
打不了嗝 ᥬ᭄1 天前
Git 原理与使用
git·gitee
m0_614619061 天前
花了一下午学 Git,整理了一份学习笔记
笔记·git·学习
AGV算法笔记1 天前
解决Git> git add -A -- fatal: CRLF would be replaced by LF in Test/Test.cpp
git
Dontla1 天前
VSCode插件Git Graph介绍(Git可视化管理分支、可视化Git)
ide·git·vscode
Echoo华地1 天前
用git diff快速比较文件夹差异并生成报告
linux·git·unix·repository·diff·branch
勤劳打代码1 天前
防微杜渐 —— 为什么一次 Sync 会变成一次 merge?
git·团队管理
dyxal1 天前
Windows 下 Git 离线安装与 VS Code 便携版集成完全指南
windows·git·elasticsearch