本文介绍了Git存储单个未跟踪文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我有几个编辑过的文件,如下所示,还有一些新创建的文件



现在我想存储未跟踪文件(在这种情况下,它是 db / migrate / 20161212071336_add_paranoid_fields.rb ,但不能隐藏更改的文件)。



我该怎么做?



为什么我要隐藏一个未跟踪文件



我首先创建了这个文件,然后我意识到我不需要它立即(它需要被删除,以便我的程序正常工作);但我将来可能需要它。



我搜索过的东西(而不是给我一个答案),以及他们没有帮助的原因







    • 这会隐藏所有文件;我只想保留一个文件。





    • 它建议使用 stash -p ,但这只会隐藏跟踪的文件。
    • >

      解决方案

      如果您只有一个未跟踪的文件,您可以执行: $ b

        git add -u 
      git stash --include-untracked --keep-index

      这样只会将未跟踪的文件添加到存储中,并将它们从工作目录中删除。



      如果您有多个untraked文件,并且想要要包含这一个到存储,那么你将不得不做一个提交,然后存储单个文件,然后重置

        git add -u 
      git commit -mtemp commit
      git add my_file_to_stash
      git stash
      git reset --hard HEAD ^
      code>

      这里精妙的是,当您稍后恢复存储时,该文件将被添加到索引中。这可能是一件好事,因为它会提醒你这个文件很重要。


      Question:

      I have a couple of edited files as listed below, and also I have some newly created files

      Now I want to stash the untracked file (in this case, it's db/migrate/20161212071336_add_paranoid_fields.rb, but not stash the changed files).

      How should I do that?

      Why I want to stash a single untracked file

      I created this file at first, and then I realised that I don't need it immediately (it needs to be deleted in order for my program to work correctly); but I might need it in future.

      What I've searched (and not giving me an answer), and the reason why they don't help

      解决方案

      If you only have this one untracked file you can do:

      git add -u
      git stash --include-untracked --keep-index
      

      And that will add only untracked files to the stash, and remove them from the working directory.

      If you have several untraked files and you want to include just this one to the stash, then you will have to do a commit, then the stash of the single file and then a reset

      git add -u
      git commit -m "temp commit"
      git add my_file_to_stash
      git stash
      git reset --hard HEAD^
      

      The subtlely here is that when you recover the stash later, that file will be added to the index. That is probably a good thing, as it will remind you that this file is important.

      这篇关于Git存储单个未跟踪文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 03:56