
On 2013-12-14 09:37, Jason White wrote:
Matthew Cengia <mattcen@gmail.com> wrote:
Keep in mind that by its very nature, git would not stage unchanged files, because it would hash the file, determine immediately via hash table that the hash already existed in the object store, and not bother to store it again. It *does* have to go through the entire process of *calculating* the hash for each file every time though, as far as I know.
does it exclude unchanged files based on the last modification time? If so, it only needs to look at the directory entries. It already has the date/time of the commit relative to which changes are to be calculated.
No, it does not check the datestamp, and nor should it; git doesn't track the modification dates of individulal files, it only cares about the date of commits, and heavy-weight tags. If it checked the date, the below example would allow me to trick git, and the user, into thinking the repo was unchanged, when in fact I'd changed the entire contents of file 'bar'. When it comes to files, git only cares about one thing: The sha1sum of the file. Elegant in its simplicity, even if it does take a bit longer to read data in order to verify its integrity. mattcen@owen:tmp$ git init Initialized empty Git repository in /tmp/tmp/.git/ mattcen@owen:tmp(master)$ echo foo > bar mattcen@owen:tmp(master)$ git add bar mattcen@owen:tmp(master)$ git commit -m "initial commit" [master (root-commit) bd218a4] initial commit 1 file changed, 1 insertion(+) create mode 100644 bar mattcen@owen:tmp(master)$ cp -a bar baz mattcen@owen:tmp(master)$ echo quz > bar mattcen@owen:tmp(master)$ touch -r baz bar mattcen@owen:tmp(master)$ ls -l --time-style=full-iso total 8 -rw-rw-r-- 1 mattcen mattcen 4 2013-12-14 10:21:07.000000000 +1100 bar -rw-rw-r-- 1 mattcen mattcen 4 2013-12-14 10:21:07.000000000 +1100 baz mattcen@owen:tmp(master)$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: bar # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # baz no changes added to commit (use "git add" and/or "git commit -a") -- Regards, Matthew Cengia