问题
There are number of questions which try to map the CVS ability of cvs diff -D "1 days ago"
to git:
Git - How can I list all files changed on the master branch between two times?
How can I get the diff between all the commits that occurred between two dates with Git?
But from my understanding from the comments in this question:
Does copying the Git bare repo change the log?
performing git diff --name-only master@{"5 day ago"} master
is local to your machine and can not resolve issues with merges into master.
I'm thinking that I need to use git whatchanged
and based on another question (Bash script to extract filenames from git whatchanged) perhaps
git show --pretty="format:" --name-only HEAD^
but at best I seem to be thinking I have to concoct a somewhat fragile script to parse various git outputs for particular refs falling within certain dates and then redirect those refs to other git commands to isolate what files were modified in those refs, and finally concat the results.
I just am shocked that this hasn't already been provided by git already as I feel it is a somewhat fundamental feature, particularly because, from the questions that I have mentioned above, git is not fully reproducing the wonderful advantages of cvs diff -D "1 days ago"
and if CVS has something on git, then well, I've lost all faith in humanity.
Can someone prove me wrong? Is there a way to reliably query if any files in master have been updated, via a merge or commit, since a period of time?
The Problem
Here is what I did that led me here:
- Make a number of commits to your repository and push them to origin
- Now take the bare repository and copy it with
cp -r --preserve
- From this copied bare repository, execute
git clone copy_of_everything
- In
copy_of_everything
rungit diff --name-only master@{"5 day ago"} master
or however long its been since you made those commits in step 1.
You will find, at least I did, that the git diff --name-only master@{"5 day ago"} master
is unable to find any commits not done since you performed the clone.
This is what seems so unacceptable. The logs are there telling me what I need to know in long-form, but no one or two commands that I am aware of can tell me which files have been modified since a certain date.
Update 1
sleske's comment seems to hit the nail on the head. git diff --name-only master@{"5 day ago"} master
, being based on the reflog, is a bad idea because it's based on local modifications to the repository state.
So is there a nice alternative?
Also, kudos to User:qqx for pointing me in this direction with this question in the first place.
Update 2
And there is. And sleke's (now accepted) answer explains why.
In short, I needed to perform:
git diff --name-only $(git log --until="1 days ago" -n1 --format=%H master ) master
Faith in humanity restored.
回答1:
Unfortunately, I'm not very familiar with cvs diff -D
. I assume it shows all changes made to files since the time given. If you want that with git, you can do:
git log --until="1 days ago" -n1 --format=%H
This will print the last commit on master that is older than 1 day.
Then use the ID of that commit to get a diff between the commit from one day ago, and the current HEAD (i.e. current state of the branch):
git diff <ID from step before> HEAD
This will print a full diff. To just get a list of files, add option --stat
to the end. This will give you a summary, like:
a/data.c | 14 ++++++++
b/stuff.c | 2 +-
b/code2.c | 54 +++++++++++++++++------
I don't know any way to do it with a single command; of course you could just combine both in one line (assuming you use bash
):
git diff $(git log --until="1 days ago" -n1 --format=%H) HEAD
Note: This will also pick up changes to files caused by a merge. It just compares the states of the repository at the two commits given (old commit, and HEAD).
回答2:
git diff "master@{a month ago}".."master@{last week}"
gives the differences between those dates from the reflog, do a whatchanged
and a bit of post-massage will give you the changed files.
来源:https://stackoverflow.com/questions/14906503/git-how-can-i-reliably-query-if-any-files-in-master-have-been-updated-via-a-m