Search code examples
gitgitignore

git - ignore files by timestamp


My Situation is this: I work on a modification for an old game with source code. There are a lot of files. Since it is an old game, all files that haven't been changed by me have an old file change timestamp.

It would be really helpful for me if I could only add the files to the repository (track them), that have been changed recently (by me). That way it would be really easy to see at once which files have been changed and it would make it easier to automatically package them.

I could write a program which tracks the timestamps of all files in the background and changes dynamically the gitignore file. But is it possible to do such things with git onboard tools?

Greetings,

Neconspictor


Solution

  • I do not know of a git tool to do this. The obvious location would be in the gitignore tool, but it only works with file patterns. You will have to generate this file list independently. Since your files are just local, the file list do not need to be pushed to the git server, so $GIT_DIR/info/exclude sounds like the right location to put the list.

    In your case, you can generate the list with something like (e.g. for 2015-03-22 at 15:30):

    touch -t 201503221530 timestamp_file
    find . ! -newer timestamp_file > .git/info/exclude
    

    However, if not too troublesome I would generally advise to track everything in git:

    • Unchanged files are not usually disturbing
    • It is straightforward to get the list of changed files between commits (git diff --name-only <sha1> <sha2> or git diff --name-only <sha1> HEAD)
    • Suppose you currently edited (thus track) only files A and B, then you start editing file C. You'll need to remember to add and commit file C before you start working on C in order to track future changes. Wouldn't it be easier to have C tracked already? (Here, there should be a way to use some git hooks, e.g. a pre-commit hook, to check that all files in .git/info/exclude are older than timestamp_file, and refuse the commit if that is not the case.)
    • With this ABC example, when you want to get all your changes, you can't make a simple git diff --name-only <sha1> HEAD anymore, because it will include adding C before your changes. So it is in no way "easier to automatically package them", it is indeed much harder.