Git:如何存储'git stash'数据

Git: How to store 'git stash' Data

我在我的开发分支中有一些特殊的未提交的更改,我使用 git stash 命令隐藏了它们,我正在使用 git pop 命令重新应用这些隐藏的更改。

但是我想保留这个特定的状态(如果可能的话,我可以用某种文本格式)。

因为有很多次我有一些未提交的更改,这些更改并不特别,我这样做只是为了分支更改 activity 所以我特定的隐藏更改会重叠(删除)。所以我想保留那个特定的藏品。

如果可能的话,我是否有机会保留某些文件中的特定隐藏更改?

使用apply代替pop:

git stash apply

您还可以应用一些特定的存储(不是最近的)。以下命令将应用第二个最近的存储(索引从 0 开始,这是最近的存储):

git stash apply stash@{1}

同样适用于 pop。

pop 实际上等同于这两个命令:

git stash apply
git stash drop

查看 git-stash documentation 了解详情。

Because there are many times I have some uncommitted changes which are not particular I am doing that just sake for branch changing activity so my particular stashed changes get overlapped(removed). So I want to preserve that particular stash.

您可以拥有多个藏品

git stash list

stash@{0}: WIP on master: 686b55d Add wolves.
stash@{1}: WIP on gerbils: b2bdead Add dogs.
stash@{2}: WIP on gerbils: b2bdead Add dogs.

藏匿处名称显示在列表中。并为您提供保存在 stash 堆栈中的 stash 列表。

$ git stash apply stash@{1}
# On branch gerbils
# Changes not staged for commit:
#
# modified: index.html

stash@{0}是应用时默认的;指定要应用的存储名称 一个不同的

git stash apply <stash-name>

希望对你有帮助!!!

如果要将存储保存到文件中,运行:

git stash show -p stash@{1} > <file-path>

如果你想把它应用回来,运行:

git stash apply < <file-path>