Git:将文件拖放到存储中而不应用 [英] Git: drop file in a stash without applying it

查看:58
本文介绍了Git:将文件拖放到存储中而不应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

令我惊讶的是,我没有找到对此问题的答复,但基本上是说我有一个藏有多个文件的存储库(例如,可以通过git扩展来探索它).查看其内容,我想在应用它之前先删除一些文件,这可能吗?

I am surprised not having found a response to this question but basically say I have a stash with several files in it (I can explore it through git extension for instance). Looking at its content, I'd like to drop some files before applying it, is it possible ?

我能想到的唯一解决方法是:

The only workaround I can think of is:

  1. 将存储区签到新分支
  2. 检出目标文件
  3. 再次藏起
  4. 删除分支

还有更好的东西吗?

谢谢

推荐答案

您可以直接使用stash@{0}作为提交引用.

You can directly use stash@{0} as a commit reference.

如果您的工作树是干净的(没有修改过的文件),则可以检出所需的文件:

If your working tree is clean (no modified files), you can checkout the files you want :

git checkout stash@{0} -- file1 file2 file3

,然后手动检查差异以保留所需的内容.

and then inspect the diff manually to keep what you want.

如果您想要更接近git stash apply的行为,则可以创建并应用补丁:

If you want something closer to the behaviour of git stash apply, you can create a patch and apply it :

git show -p stash@{0} -- file1 file2 file3 | git apply -


列出在stash@{0}中修改的文件:


To list the files modified in stash@{0} :

git diff --name-only stash@{0}^ stash@{0}

如果要获取除一个文件外的所有文件:

If you want to get all files except one :

git show -p stash@{0} -- $(git diff --name-only stash@{0}^ stash@{0} |\
                           grep -v "thefile")

这篇关于Git:将文件拖放到存储中而不应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆