sirtet
sirtet

Reputation: 85

'git add' based on file last modified date?

If i have a GIT repo where a number of edits have been done without commits, how can i best deal with that?

I could add files based on modified-date.

I can list all files by edit-date as described here: git status - list last modified date

But

  1. If there's lots of files, how to feed all files with a specific date (or date-range) into a git add command?
  2. Deleted files can't be tied to a date, so they'd need to go into a separate commit. So the resulting "deleted-commit" and the "dates-commits" would need to be in kind of a "commit-group" i guess. Maybe mark in the commit message that deletes from that date are in a different commit?
    Are there any best-practices for that?

Upvotes: 0

Views: 415

Answers (1)

j6t
j6t

Reputation: 13627

You can use a typical find | xargs construct:

# up to 2 days (48 hours) ago
find . -type f -mmin +2880 -print0 | xargs -0 git add
git commit
# up until yesterday (24 hours ago)
find . -type f -mmin +1440 -print0 | xargs -0 git add
git commit
# all the rest
git commit -a

-mmin takes the number of minutes, prepend the number with a + to say "more than that". If your edits have been separated by days, you can use -mtime instead because that takes the number of days, which may be easier to count than the number of minutes.

Insert commits for deleted files as appropriate. There is no way to tell when they were deleted, though.

Of course, this will be useful only if all edited files are independent. If a file has been edited twice, and the change after the first edit should have been committed, you are screwed because you do not have that state anymore.

Upvotes: 3

Related Questions