简体   繁体   中英

How to list files by when it was first added to a Git repo?

How do you find the most recently added files in git, on a Linux OS?

Using git log on every file is not feasible.

And git ls-files shows the full list of files, but I don't see any dates associated with them.

git log --name-status --diff-filter=A

See the docs about --diff-filter .

You don't need to run git log on "every file". You only need to run it once. Use something like git log --name-status --format=%H which produces output like this:

aa56a2ff6a56697342908cc0cc85a537ecea4325

A   changelogs/fragments/70887_galaxy_token.yml
M   lib/ansible/galaxy/token.py
932ba3616067007fd5e449611a34e7e3837fc8ae

M   lib/ansible/module_utils/basic.py
M   lib/ansible/modules/get_url.py
A   test/integration/targets/unsafe_writes/aliases
A   test/integration/targets/unsafe_writes/basic.yml
[...]

For each commit, this lists the files involved and their status, where M is "modified", A is added, etc.

Now just look for lines that start with A<tab> :

$ git log --name-status --format=%H | awk -F'\t' '$1 == "A" {print}'
A       changelogs/fragments/70887_galaxy_token.yml
A       test/integration/targets/unsafe_writes/aliases
A       test/integration/targets/unsafe_writes/basic.yml
[...]

The most recently added files are the ones at the top of the list.

Creation dates, but it still takes a long time:

for file in $(git ls-files); do echo -n "$file "; git log --format=%ai $file | tail -1; done

Last modified dates is the same but use head instead of tail:

for file in $(git ls-files); do echo -n "$file "; git log --format=%ai $file | tail -1; done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM