【问题标题】:Find files with particular removed text and stage them in git查找具有特定已删除文本的文件并将它们暂存到 git
【发布时间】:2022-08-02 18:37:19
【问题描述】:

假设我已经从存储库中的许多文件中删除了文本 \'foo\',并且我想提交该更改。

但也有很多不相关的变化。

如何找到这些文件并暂存它们?

    标签: git


    【解决方案1】:

    git grep--cached 选项似乎在搜索更改为联合国上演(看起来像一个错误,因为它不是它的文档所说的,也不是git diff 如何对待它的--cached 选项)。

    git grep --cached foo 得到:

    somefile.txt: foo: true
    

    要暂存这些文件,请使用 cut 仅提取文件名:git grep --cached foo | cut -d : -f 1

    somefile.txt
    

    然后 xargs 暂存该列表:git grep --cached foo | cut -d : -f 1 | xargs git add

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      • 2010-10-19
      • 2017-08-26
      • 2022-01-24
      • 2011-05-14
      • 2012-03-24
      • 2012-09-04
      相关资源
      最近更新 更多