简体   繁体   English

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

[英]Is it possible to drop a single file from git stash?

是否有可能,没有pop整个存储并保存另一个没有这个特定的文件?

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' 如果你迷失了藏匿号码,你也可以使用git stash save 'some other changes'

At some point (probably nearer than you think) it's easier to keep track of real branches. 在某些时候(可能比你想象的更近),更容易跟踪真正的分支。

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 : git update-index手册页

--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. 当“假定未更改”位打开时,git停止检查工作树文件是否有可能的修改,因此您需要手动取消设置该位以在更改工作树文件时告诉git。
This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (eg cifs ). 当在具有非常慢的lstat(2)系统调用(例如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) 此选项还可以用作粗略的文件级机制,以忽略跟踪文件中未提交的更改(类似于.gitignore对未跟踪文件的更改)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM