如何仅固定某些文件? [英] How to unstash only certain files?

查看:81
本文介绍了如何仅固定某些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我隐藏了我的改变。现在我只想从存储中取出一些文件。我该如何做到这一点?

>在下面提到,并在如何从git中提取单个文件(或更改为文件)隐藏?,您可以申请使用 git checkout git show 来恢复特定文件。

  git checkout stash @ {0}  - < filename> 

(As Jaime M. 评论。 ,对于像tcsh这样需要转义特殊字符的shell,语法是: git checkout'stash @ {0}' - < filename>


或将它保存在另一个文件名下:



  git show stash @ {0}:<完整文件名> > < newfile中> 




(请注意这里< full filename> ; 是文件相对于项目顶部目录的完整路径名(think:相对于 stash @ {0} ))。


yucer 建议在评论中:


如果您想手动选择要从该文件应用哪些更改:



  git difftool stash @ {0} .. HEAD  - < filename> 

Vivek 在评论中添加了


看起来像 git checkout stash @ {0} - < filename> 在存储器执行时恢复文件的版本 - 它不会 应用(仅)该文件的存储更改。

要做后者:



  git diff stash @ {0} ^ 1 stash @ {0}  -  - <文件名> | git apply 



(as peterflynn 评论 a>,在某些情况下,您可能需要 | git apply -p1 ,从传统中删除一个( p1 ) diff路径)



正如评论:unstash( git stash pop ),然后:




  • 在索引中添加要保留的内容( git add
  • 存储其余部分: git stash --keep-index



最后一点是允许你保留一些文件,同时隐藏其他人。

它在如何从多个已更改的文件中只存储一个文件


I stashed my changes. Now I want to unstash only some files from the stash. How can I do this?

解决方案

As mentioned below, and detailed in "How would I extract a single file (or changes to a file) from a git stash?", you can apply use git checkout or git show to restore a specific file.

git checkout stash@{0} -- <filename>

(As commented by Jaime M., for certain shell like tcsh where you need to escape the special characters, the syntax would be: git checkout 'stash@{0}' -- <filename>)

or to save it under another filename:

git show stash@{0}:<full filename>  >  <newfile>

(note that here <full filename> is full pathname of a file relative to top directory of a project (think: relative to stash@{0})).

yucer suggests in the comments:

If you want to select manually which changes you want to apply from that file:

git difftool stash@{0}..HEAD -- <filename>

Vivek adds in the comments:

Looks like "git checkout stash@{0} -- <filename>" restores the version of the file as of the time when the stash was performed -- it does NOT apply (just) the stashed changes for that file.
To do the latter:

git diff stash@{0}^1 stash@{0} -- <filename> | git apply

(as commented by peterflynn, you might need | git apply -p1 in some cases, removing one (p1) leading slash from traditional diff paths)

As commented: "unstash" (git stash pop), then:

  • add what you want to keep to the index (git add)
  • stash the rest: git stash --keep-index

The last point is what allows you to keep some file while stashing others.
It is illustrated in "How to stash only one file out of multiple files that have changed".

这篇关于如何仅固定某些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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