是否可以从 git stash 中删除单个文件?

发布于 2024-09-07 12:18:10 字数 35 浏览 6 评论 0原文

是否可以不弹出整个存储并保存另一个没有此特定文件的存储?

Is it possible, without pop whole stash and save another without this particular file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诺曦 2024-09-14 12:18:10

简短的回答:不,这不是堆栈的工作原理。您可以执行以下操作来获得您想要的结果。

假设您存储了一些其他更改,然后对索引进行了一些修改(原始更改),并且您决定在修改存储时保留这些更改:

#verify the state you are in
git stash list
git status

git stash #push work in progress on the stash
git stash list #check which stash you need
git stash show stash@{1} #check the changes in the stash

git stash pop stash@{1} #you're now ready to change your 'other' changeset
# hack hack
git stash #modified 'other' change set pushed on the stash
git stash pop stash@{1} #your 'original changes'

我建议使用此工作流程,而不是尝试直接修改存储。如果您迷失在存储数字中,您还可以使用git stash save '一些其他更改'

在某个时刻(可能比您想象的更近)更容易跟踪真实的分支。

Short answer: no, that's not how the stack works. You can do the following though to get the result you're looking for.

Assuming that you have stashed some other changes, then made some more modifications to your index (original changes) and you decide that you want to keep these changes while modifying the stash:

#verify the state you are in
git stash list
git status

git stash #push work in progress on the stash
git stash list #check which stash you need
git stash show stash@{1} #check the changes in the stash

git stash pop stash@{1} #you're now ready to change your 'other' changeset
# hack hack
git stash #modified 'other' change set pushed on the stash
git stash pop stash@{1} #your 'original changes'

I'd recommend this workflow over trying to modify the stash directly. If you get lost in stash numbers you can also use git stash save 'some other changes'

At some point (probably nearer than you think) it's easier to keep track of real branches.

素衣风尘叹 2024-09-14 12:18:10

您可以尝试在弹出堆栈后将您不想存储的文件标记为“unchanged”:,

git  update-index --assume-unchanged -- /path/to/file

然后尝试存储,检查是否包含该文件。

git update-index 手册页

--assume-unchanged
--no-assume-unchanged

指定这些标志后,为路径记录的对象名称不会更新。
相反,这些选项设置和取消设置路径的“假定不变”位。

当“假设不变”位打开时,git 停止检查工作树文件是否有可能的修改,因此您需要手动取消设置该位以告诉 git 当您更改工作树文件时。
当在 lstat(2) 系统调用(例如 cifs)非常慢的文件系统上处理大型项目时,这有时会很有帮助。

此选项还可以用作粗略文件级机制,以忽略跟踪文件中未提交的更改(类似于 .gitignore 对未跟踪文件所做的操作)

You could try, after popping your stack, to mark the file you don't want to stash as "unchanged":

git  update-index --assume-unchanged -- /path/to/file

, and then try to stash, checking if said file is included or not.

git update-index man page:

--assume-unchanged
--no-assume-unchanged

When these flags are specified, the object names recorded for the paths are not updated.
Instead, these options set and unset the "assume unchanged" bit for the paths.

When the "assume unchanged" bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file.
This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文