代码之家  ›  专栏  ›  技术社区  ›  kittygirl

如何从另一个文件夹和文件列表中减去?

  •  0
  • kittygirl  · 技术社区  · 6 年前

    我有一个git repo,如下所示:

    [root@localhost www]# tree
    .
    ├── admin.php
    ├── api
        ├── index.htm
        └── remote
            └── mod
                ├── index.htm
                ├── mod_cron.php
                └── mod_index.php
    
    
    3 directories, 5 files
    

    很容易得到Git跟踪的文件夹和文件列表。

    [root@localhost www]# git ls-files >a.txt
    [root@localhost www]# cat a.txt
    .gitattributes
    .gitignore
    admin.php
    api/index.htm
    api/remote/mod/index.htm
    api/remote/mod/mod_cron.php
    api/remote/mod/mod_index.php
    

    但在工作目录中,有些文件夹和文件没有被git跟踪。整个工作目录如下:

        [root@localhost www]# tree
        .
        ├── admin.php
        ├── api
        │   ├── index.htm
        │   └── remote
        │       ├── index.htm
        │       ├── index.php
        │       └── mod
        │           ├── index.htm
        │           ├── mod_cron.php
        │           └── mod_index.php
        ├── archiver
           └── index.php
    
    4 directories, 8 files
    

    如何获取Git未跟踪的文件夹和文件列表,如下所示 :

    archiver/
    archiver/index.php
    api/remote/index.htm
    api/remote/index.php
    

    我想在 rsync -av --files-from=/path/to/not_tracked_files_lsit .
    事先谢谢!

    1 回复  |  直到 6 年前
        1
  •  0
  •   Paul Hodges    6 年前

    基本上是从上面的评论中复制…

    find 会给你一份完整的文件清单。

    find | grep -v '[.]git/' | grep -vf a.txt
    

    应该从回购本身和所有跟踪文件中消除垃圾。

    另一个选择,可能更好:

    git status -s | sed -n '/^[^?]/d; s/^?? //; p;'
    

    这应该做很多相同的事情,但希望有一点清洁,更多的重点,与较少的进程在管道中。