Using the hook mechanism of gitProgramAutomatically generate version information
1. Git init. Create a git repository and you will find a pile of *. Sample Under the. Git/hooks directory.
2. Locate the post-commit.sample, post-commit indicates commitCodeAfter the command is triggered, remove the suffix
3. Add a command at the end of the file to automatically generate a header file containing the hash value after submission:
Exec git log -- pretty = format: 'static tchar * ghash = _ T ("% H"); '-N 1>./. Git/latesthash. h
4.Source codeAdd the header file generated by git to use the latest hash value. The following code uses hash to track the software version:
# Include ".../. Git/latesthash. H" bool cmfcdemodlg: oninitdialog () {This-> setdlgitemtext (idc_edit_hash, ghash );
5. Submit the code, trigger the command execution in. Git/hooks/post-commit, and automatically generate the header file.
6. Re-compile the project, and the hash value takes effect.