git - 如何列出自特定日期以来尚未更改的所有文件?

时间:2015-07-16 00:59:25

标签: git

我正在尝试获取存储库中自某个日期以来未被触及的文件列表。

我尝试使用git log --before="X months ago" --name-only,然后将该列表与git log --after="X months ago" --name-only进行比较,但我不确定是否有更简单的方法?

是否有办法获取每个文件的HEAD提交日期并过滤列表?我不确定最好的办法是什么。

3 个答案:

答案 0 :(得分:5)

可能有更好的方法可以做到这一点,但这应该有效:

git diff --name-only --stat @{2.weeks.ago} >> changed.txt && git ls-files >> all.txt && comm -23 all.txt changed.txt >> unchanged.txt

它的作用,

1:抓取所有已更改的文件名,并创建一个名为changed.txt的文本文件 2:抓取仓库中的所有文件名,并创建一个名为all.txt的文本文件 3:使用comm命令抑制两个文件之间的公共线,并输出到名为unchanged.txt

的文件

希望这有帮助,

感谢朋友(Adam Morse)的解决方案。

答案 1 :(得分:4)

您可以遍历每个文件并显示其修改时间,即:

git ls-tree -r --name-only HEAD | while read filename; do
  echo "$(git log -1 --format="%ad" -- $filename) $filename"
done

这将产生如下输出:

Fri Dec 23 19:01:01 2011 +0000 Config
Fri Dec 23 19:01:01 2011 +0000 Makefile

PS :您还可以使用: - 格式="%ai" (我的偏好)代替--format =&#34 ;%广告"为了更好的可分类时间戳。

使用 - format ="%ai" ,输出将显示为:

2015-05-03 21:47:26 -0500 v1/ansible/runner/lookup_plugins/consul_kv.py
2015-05-03 21:47:26 -0500 v1/ansible/runner/lookup_plugins/csvfile.py
2015-05-03 21:47:26 -0500 v1/ansible/runner/lookup_plugins/dict.py
2015-05-03 21:47:26 -0500 v1/ansible/runner/lookup_plugins/dig.py
2015-05-04 01:33:10 -0500 lib/ansible/plugins/filter/__init__.py
2015-05-04 01:33:10 -0500 lib/ansible/plugins/filter/mathstuff.py
2015-05-05 15:24:36 +0200 docs/man/man1/ansible-playbook.1
2015-05-05 15:24:36 +0200 docs/man/man1/ansible-pull.1
2015-05-07 12:22:08 +0100 docsite/rst/playbooks_tags.rst
2015-05-07 22:24:33 +0000 ISSUE_TEMPLATE.md
2015-05-07 23:56:33 -0500 lib/ansible/plugins/cache/redis.py
2015-05-08 13:49:10 -0700 test/units/playbook/test_block.py
2015-05-11 08:06:21 -0400 lib/ansible/module_utils/openstack.py
2015-05-11 22:56:56 -0400 docsite/rst/playbooks_roles.rst
2015-05-12 12:18:55 -0400 v1/ansible/utils/module_docs_fragments
2015-05-12 12:24:57 -0500 test/units/executor/test_play_iterator.py
2015-05-12 12:24:57 -0500 test/units/playbook/test_play.py
2015-05-13 11:04:12 -0700 test/integration/roles/test_bad_parsing/tasks/scenario1.yml
2015-05-14 12:24:36 +0200 docsite/rst/intro_patterns.rst
2015-05-16 15:45:01 -0500 test/units/template/test_safe_eval.py
2015-05-16 15:45:01 -0500 test/units/template/test_vars.py
2015-05-17 01:29:40 -0500 test/units/module_utils/__init__.py
2015-05-17 01:29:40 -0500 test/units/module_utils/test_database.py
2015-05-18 17:26:59 -0700 test/units/plugins/action/__init__.py
2015-05-18 17:26:59 -0700 test/units/plugins/cache/__init__.py
2015-05-18 17:26:59 -0700 test/units/plugins/cache/test_cache.py
2015-05-18 22:44:29 +0200 test/integration/roles/test_cs_firewall/tasks/main.yml
2015-05-19 08:58:27 -0400 test/integration/cloudstack.yml
2015-05-19 15:37:47 -0500 test/integration/roles/test_rax_scaling_group/files/test.txt
2015-05-19 15:37:47 -0500 test/integration/roles/test_rax_scaling_group/meta/main.yml
2015-05-21 12:24:41 -0700 test/integration/roles/test_uri/files/testserver.py
2015-05-23 21:37:12 +0200 test/units/inventory_test_data/group_vars/noparse/all.yml~
2015-05-23 21:37:12 +0200 test/units/inventory_test_data/group_vars/noparse/file.txt
2015-05-23 21:37:12 +0200 test/units/inventory_test_data/group_vars/parse/all.yml
2015-05-27 13:39:09 -0700 test/integration/roles/test_mysql_db/tasks/main.yml
2015-05-28 15:26:03 -0500 hacking/module_formatter.py
2015-05-28 15:26:03 -0500 v1/tests/inventory_test_data/simple_hosts
2015-05-28 15:26:03 -0500 v1/tests/TestInventory.py
2015-05-29 21:49:52 -0400 docsite/rst/guide_aws.rst
2015-05-30 11:35:55 +0200 lib/ansible/utils/module_docs_fragments/cloudstack.py
2015-05-31 23:15:28 -0400 test/integration/roles/prepare_win_tests/meta/main.yml
2015-05-31 23:16:45 -0400 test/integration/test_winrm.yml
2015-06-01 16:41:52 -0500 lib/ansible/parsing/yaml/dumper.py
2015-06-01 21:53:49 +0100 test/integration/roles/test_win_copy/tasks/main.yml
2015-06-02 11:43:35 -0700 packaging/rpm/ansible.spec
2015-06-02 23:39:57 -0400 lib/ansible/utils/path.py
2015-06-02 23:42:00 -0400 lib/ansible/plugins/lookup/password.py
2015-06-03 13:27:31 -0700 lib/ansible/plugins/inventory/__init__.py
2015-06-03 21:19:11 +0200 lib/ansible/module_utils/f5.py
2015-06-03 22:19:26 -0400 hacking/templates/rst.j2
2015-06-04 11:34:56 -0500 v1/ansible/utils/module_docs.py
2015-06-04 15:43:07 -0400 lib/ansible/executor/module_common.py
2015-06-05 07:25:37 -0400 test/integration/roles/test_failed_when/tasks/main.yml
2015-06-05 15:34:37 -0500 test/units/module_utils/test_basic.py
2015-06-06 09:13:14 -0500 lib/ansible/playbook/helpers.py
2015-06-08 19:32:44 -0400 docsite/rst/playbooks_intro.rst
2015-06-09 11:45:53 -0400 lib/ansible/plugins/action/package.py
2015-06-10 15:42:30 +0200 README.md
2015-06-11 13:03:25 -0400 test/units/mock/loader.py
2015-06-11 13:43:47 -0400 lib/ansible/plugins/lookup/file.py
2015-06-12 12:32:02 -0700 lib/ansible/plugins/lookup/url.py
2015-06-15 17:42:40 -0400 test/integration/roles/test_lookups/vars/main.yml
2015-06-16 11:00:03 -0400 docsite/_themes/srtd/layout.html
2015-06-16 14:20:34 +0000 v1/ansible/module_utils/powershell.ps1
2015-06-17 23:31:31 -0400 lib/ansible/plugins/connections/paramiko_ssh.py
2015-06-19 23:04:35 -0400 lib/ansible/template/vars.py
2015-06-21 01:24:35 -0400 lib/ansible/plugins/connections/local.py
2015-06-21 01:51:28 -0400 lib/ansible/plugins/shell/sh.py
2015-06-22 01:17:09 -0400 lib/ansible/playbook/block.py
2015-06-22 02:06:07 -0400 lib/ansible/inventory/group.py
2015-06-23 08:52:57 -0700 docsite/rst/quickstart.rst
2015-06-23 10:19:50 -0400 lib/ansible/playbook/role/include.py
2015-06-23 12:12:38 -0400 lib/ansible/plugins/connections/ssh.py
2015-06-23 13:00:32 -0700 docsite/rst/intro_configuration.rst
2015-06-23 20:48:13 -0400 docsite/rst/faq.rst
2015-06-24 01:00:22 -0700 lib/ansible/plugins/connections/chroot.py
2015-06-26 23:38:06 -0700 docsite/rst/test_strategies.rst
2015-06-27 00:58:03 -0400 lib/ansible/playbook/task.py
2015-06-27 01:01:08 -0400 lib/ansible/playbook/attribute.py
2015-06-28 00:30:27 -0400 lib/ansible/playbook/conditional.py
2015-06-29 11:13:17 -0700 docsite/rst/playbooks_best_practices.rst
2015-06-30 09:38:12 -0500 test/integration/roles/test_rax_cbs_attachments/tasks/main.yml
2015-06-30 09:38:12 -0500 test/integration/roles/test_rax_cbs/tasks/main.yml
2015-06-30 16:08:46 -0400 lib/ansible/playbook/playbook_include.py
2015-07-01 01:48:19 -0400 test/units/playbook/test_playbook.py
2015-07-01 01:48:19 -0400 test/units/playbook/test_taggable.py
2015-07-01 07:23:26 -0700 .travis.yml
2015-07-01 15:10:25 -0400 lib/ansible/plugins/action/patch.py
2015-07-01 18:34:44 -0400 lib/ansible/plugins/filter/ipaddr.py
2015-07-02 14:37:51 +0100 v1/ansible/runner/filter_plugins/core.py
2015-07-02 18:59:58 +0000 hacking/test-module
2015-07-03 13:54:31 -0400 lib/ansible/plugins/lookup/sequence.py
2015-07-03 22:27:49 +0200 lib/ansible/template/__init__.py
2015-07-04 10:23:30 -0400 lib/ansible/cli/galaxy.py
2015-07-05 17:23:22 +0100 lib/ansible/module_utils/facts.py
2015-07-06 10:21:40 +0300 docsite/rst/intro_installation.rst
2015-07-06 13:15:11 -0700 lib/ansible/parsing/splitter.py
2015-07-07 11:28:20 +0200 docsite/rst/index.rst
2015-07-08 09:45:02 -0700 lib/ansible/module_utils/basic.py
2015-07-08 10:11:43 -0400 ticket_stubs/needs_template.md
2015-07-08 20:39:16 -0400 contrib/inventory/rax.py
2015-07-09 08:23:43 -0400 lib/ansible/inventory/host.py
2015-07-09 10:50:31 -0400 test/integration/credentials.template
2015-07-09 10:50:31 -0400 test/integration/roles/test_azure/tasks/main.yml
2015-07-10 01:53:59 -0400 test/integration/non_destructive.yml
2015-07-10 23:48:12 -0400 lib/ansible/plugins/callback/timer.py
2015-07-11 00:47:59 -0400 lib/ansible/plugins/callback/syslog_json.py
2015-07-11 15:01:50 -0400 lib/ansible/plugins/callback/default.py
2015-07-11 21:49:35 -0400 lib/ansible/playbook/role/__init__.py
2015-07-12 16:10:34 -0400 lib/ansible/plugins/callback/mail.py
2015-07-12 16:39:27 -0400 lib/ansible/parsing/__init__.py
2015-07-12 16:39:27 -0400 lib/ansible/playbook/role/definition.py
2015-07-12 16:39:27 -0400 lib/ansible/plugins/__init__.py
2015-07-13 10:34:44 -0400 lib/ansible/plugins/action/assemble.py
2015-07-13 11:06:03 -0400 lib/ansible/plugins/cache/jsonfile.py
2015-07-13 15:42:47 -0400 lib/ansible/cli/adhoc.py
2015-07-13 20:42:09 -0400 lib/ansible/plugins/action/raw.py
2015-07-14 00:23:17 -0400 test/integration/roles/test_command_shell/tasks/main.yml
2015-07-14 07:28:32 -0400 lib/ansible/module_utils/powershell.ps1
2015-07-14 08:05:57 -0400 test/integration/roles/test_good_parsing/tasks/main.yml
2015-07-14 10:07:46 -0400 lib/ansible/utils/module_docs.py
2015-07-14 15:59:00 -0400 test/units/executor/test_task_executor.py
2015-07-14 16:47:47 -0400 lib/ansible/modules/extras
2015-07-14 17:03:57 -0400 lib/ansible/modules/core
2015-07-14 17:33:27 -0400 lib/ansible/cli/doc.py
2015-07-15 01:55:45 -0400 lib/ansible/plugins/strategies/__init__.py
2015-07-15 15:11:46 -0400 lib/ansible/executor/task_executor.py

git 命令 ls-tree 的优点是只列出存储在存储库中的文件,跳过.git文件夹并忽略文件。

如果您将上述操作的输出发送到.txt文件,那么您可以排序(Linux排序,查看-n选项是否可以帮助)然后使用BASH命令/ one-liner来获取所有行超过给定的日期/时间戳(如上面的输出所示)。

答案 2 :(得分:0)

查找自提交后更改的文件:

git diff --name-only $thatcommit

自2月以来在当前分支上查找最早的提交:

git log @ --first-parent --since='1 feb'  --pretty=%H --reverse | sed q

所以

( 
  git log @ --first-parent --since="$date" --pretty=%H --reverse | sed q \
  | xargs git diff --name-only
  git ls-files
) \
| sort | uniq -u

列出所有已更改的文件,然后列出所有文件,然后仅打印未列出两次的文件。