【问题标题】:Stash only some of the currently modified files [duplicate]仅存储一些当前修改的文件[重复]
【发布时间】:2018-09-29 01:58:49
【问题描述】:

我有许多已更改的文件,我只想存储一些已修改的文件。

例如,我的存储库如下所示:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

      modified: main.cpp
      modified: MyClass.h
      modified: MyClass.cpp

我想只存储 MyClass.hMyClass.cpp

我找到了this question,但接受的答案似乎是错误的,投票最多的答案需要以交互方式添加每个块/文件。

有没有一种简单的方法来存储一组特定的文件?最好在单个命令中,而不必以交互方式逐个选择文件或暂存/取消暂存事物。

【问题讨论】:

标签: git git-stash


【解决方案1】:

我发现git stash push 可以用来轻松存储多个文件。

要存储示例中的文件,命令将是

 git stash push MyClass.h MyClass.cpp

其中隐藏了 MyClass.hMyClass.cpp,但单独留下了 main.cpp

this answer的编辑中找到

【讨论】:

  • 不错的发现。我忽略了git stash push
  • git stash push -- &lt;paths&gt; 不错,但要小心:它有一个删除未跟踪文件的严重错误,直到 Git 2.16.2 才修复。
  • 您在问题中链接到的 QA 中也建议您这样做:stackoverflow.com/a/45693541/1615903
猜你喜欢
  • 1970-01-01
  • 2018-04-24
  • 1970-01-01
  • 2020-04-05
  • 2020-03-29
  • 2017-11-04
  • 1970-01-01
  • 1970-01-01
  • 2017-12-30
相关资源
最近更新 更多