public Long gitHash(File input) throws IOException {
        String path = getLogicalPath(input);
        String blob = "blob " + path.length() + "\0" + path;
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
            byte[] bytes = md.digest(blob.getBytes());
            String h = byteArrayToHexString(bytes).substring(0, 7);
            return Long.parseLong(h, 16);
        }
        catch (NoSuchAlgorithmException ex) {
            throw new IOException(ex.getMessage(), ex);
        }
    }
public Long gitHash ( File input ) throws IOException { String path = getLogicalPath ( input ) ; String blob = "blob " + path . length ( ) + "\0" + path ; MessageDigest md = null ; try { md = MessageDigest . getInstance ( "SHA-1" ) ; byte [ ] bytes = md . digest ( blob . getBytes ( ) ) ; String h = byteArrayToHexString ( bytes ) . substring ( 0 , 7 ) ; return Long . parseLong ( h , 16 ) ; } catch ( NoSuchAlgorithmException ex ) { throw new IOException ( ex . getMessage ( ) , ex ) ; } }
Use git hashing algorithm.
http://stackoverflow.com/questions/7225313/how-does-git-compute-file-hashes