81

How can I have a list with all the files that were changed in the last 2 days? I know about

git log --name-status --since="2 days ago" 

but this will show me ids, dates and commit messages. All I need is the list of the file names which were changed.

Is that possible with git?

5 Answers 5

116
git log --pretty=format: --name-only --since="2 days ago"

if some files duplicate in multiple commits, you can use pipe to filter it

git log --pretty=format: --name-only --since="2 days ago" | sort | uniq
4
  • you really want to use diff with the --stat modifier. This is not ideal. Sep 23, 2011 at 1:04
  • 7
    As posted by AA git diff --stat @{2.days.ago} is shorter and cleaner. Sep 8, 2014 at 22:37
  • @AdamDymitruk but why?
    – Ejaz
    Jan 22, 2016 at 22:08
  • git diff --stat @{2.days.ago} doesn't show the full path and with long paths and multiple projects, there can easily be an overlap in paths, making the output unusable.
    – galmok
    Dec 4, 2017 at 8:26
59
git diff --stat @{2.days.ago} # Deprecated!, see below

Short and effective

Edit

TLDR: use git diff $(git log -1 --before=@{2.days.ago} --format=%H) --stat

Long explanation: The original solution was good, but it had a little glitch, it was limited to the reflog, in other words, only shows the local history, because reflog is never pushed to remote. This is the reason why you get the warning: Log for 'master' only goes back to... in repos recently cloned.

I have configured this alias in my machine:

alias glasthour='git diff $(git log -1 --before=@{last.hour} --format=%H) --stat' 
alias glastblock='git diff $(git log -1 --before=@{4.hours.ago} --format=%H) --stat' 
alias glastday='git diff $(git log -1 --before=@{last.day} --format=%H) --stat' 
alias glastweek='git diff $(git log -1 --before=@{last.week} --format=%H) --shortstat | uniq' 
alias glastmonth='git diff $(git log -1 --before=@{last.month} --format=%H) --shortstat | uniq'                                                                                                                

credits: answer below by @adam-dymitruk

6
  • 1
    This is really great. Not sure why pretty-format got more votes.
    – sevenfourk
    Jun 12, 2014 at 7:56
  • 1
    @sevenfourk At least for me, working on a big project on a slow server, this solution is a lot slower than the pretty-format one. Also, doing that you get additional information, that may generate an extra job if you're parsing the output of this with any script. So, I upvoted the other one. Feb 5, 2015 at 9:09
  • 2
    I had to change it to ` git diff --stat "@{2 days ago}"` to get it to work. (Maybe because I'm on Windows)
    – Annabel
    Oct 18, 2015 at 0:51
  • This does not work on Cocoapods/Specs because "warning: Log for 'master' only goes back to [Yesterday]" Jun 29, 2016 at 3:22
  • Long paths are cut short and prefixed with .../, potentially ruining the ouptut.
    – galmok
    Dec 4, 2017 at 8:27
3

Use the --raw option to git log:

$ git log --raw --since=2.days

See the --diff-filter part of the git log help page for the explanation of the flags shown in the --raw format. They explain what happen to the files in each commit:

   --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
       Select only files that are Added (A), Copied (C), Deleted (D),
       Modified (M), Renamed (R), have their type (i.e. regular file,
       symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
       (X), or have had their pairing Broken (B). Any combination of the
       filter characters (including none) can be used. When *
       (All-or-none) is added to the combination, all paths are selected
       if there is any file that matches other criteria in the comparison;
       if there is no file that matches other criteria, nothing is
       selected. 
1
  • ty for the --diff-filter info details. good to know abut them from now on.
    – dole doug
    Sep 22, 2011 at 8:46
3

You can do a diff of a version that's closest to 2 days ago with:

git diff $(git log -1 --before="2 days ago" --format=%H).. --stat

--stat gives you a summary of changes. Add --name-only to exclude any meta information and have only a file name listing.

Hope this helps.

1
  • combining two gits commends. That's very good to know. TY sir
    – dole doug
    Sep 22, 2011 at 8:47
3
git log --pretty="format:" --since="2 days ago" --name-only
1
  • I find this command will only show the changes of last commit.
    – Peng Qi
    Sep 21, 2011 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.