在 Git 中应用缓存
本文将介绍在 Git 中应用缓存的不同方法。它将显示应用特定 Git 缓存的步骤。
在 Git 中应用缓存
如果你不知道,我们使用 git stash list
来显示我们的 Git 缓存。
pc@JOHN MINGW64 ~/Git (main)
$ git stash list
stash@{0}: WIP on main: 78129a6 Revert "$git status"
stash@{1}: WIP on main: 195e5c3 $git status
你可以看到我们的 Git 分支中有两个缓存区。
运行 git stash apply
将指向堆栈的顶部。如下所示,如果要应用特定的缓存,则需要添加参数。
$ git stash apply stash@{stash_index}
在我们的例子中,我们想要应用索引 1
缓存。我们运行下面的命令。
$ git stash apply stash@{1}
Removing text.txt.txt
CONFLICT (modify/delete): Tutorial.txt deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of Tutorial.txt left in tree.
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: text.txt.txt
modified: text.txt.txt.bak
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by us: Tutorial.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
.bash_history.bak
Delftscopetech/
New folder/
file.patch
但是,在应用时,此命令不会从你的列表中删除缓存。你应该运行一个 git stash pop
命令。
git stash apply
和 git stash pop
之间存在差异,后者应用更改并从你的列表中删除缓存。
让我们看一个例子。
pc@JOHN MINGW64 ~/Git/Delftscopetech (main)
$ git stash pop stash@{0}
Removing README.md
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: README.md
no changes added to commit (use "git add" and/or "git commit -a")
Dropped stash@{0} (1531151482186b97f47e9b852ac29ddd194bd099)
我们可以看到 Git 应用了我们的缓存并将其从上面的输出中删除。
另一种方法是运行 git stash drop stash@{Index}
。要清除所有缓存,请运行 git stash clear
命令。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。