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

时间:2019-01-04 14:24:50

标签: bash git

我有一个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 个答案:

答案 0 :(得分:0)

基本上从上面的评论中复制...

find将为您提供完整的文件列表。

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

应该从存储库本身和所有跟踪的文件中消除废话。

另一个选择,可能更好:

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

这应该做同样的事情,但希望可以做得更干净一点,并且要点更多,管道中的进程更少。

相关问题