Git add revision number to file on commit
Hey I’m wondering if there is a way in git to make a copy of a specific file and rename it with a revision number on commit (if there has been a change made).
For example if I had a file called ‘code.js’, when I make a change to it and commit, I want to be able to make it ‘code-1.0.0.js’ while keeping the original (or last copy).
- Visual Studio 2015 Team Explorer Git branches not working properly
- Testing and Managing database versions against code versions
- Difference between a Git commit modified and Git commit new file
- Git creates extra branch when merging
- Git ignore files being tracked WITHOUT DELETING THEM
- Where should you store 3rd party assemblies?
I know this isn’t a big deal to do manually, just wondering if there is a better way using git.
2 Solutions collect form web for “Git add revision number to file on commit”
You can automate the generation of that file by a script that you can version and register in a
That would mean that, on
code-1.0.0.js would automatically be generated (as a private file, not versioned in the git repo), for the local repo owner to use.
The version can be computed from a
git describe --abbrev=4 HEAD
You could use git hooks. Create a file named
pre-commit in the folder
.git/hooks (below the root of your repository) with this content
#!/bin/sh cp -f code.js code-1.0.0.js git add code-1.0.0.js
Then, when you commit, the contents of
code.js will be copied to
code-1.0.0.js and that file will also be committed.
pre-commit script is in bash, so you can improve it to work the way you want. For instance, you could increase the version number in the file name.
However, the concept of having version numbers embedded in file names does feel like it is going against the grain of Git. If you want file versions for the sake of HTTP caching, you would probably be better off using some functionality for that built into your web development environment or web server.