问题
What's the way to go if I want to have a consistent style standard versioned? I want to achieve two things:
- Pressing
ctrl-k,ctrl-f
(auto indenting) formats the code based on a shared standard - Stylecop runs against shared rules
What files do I have to add in my git repository to achieve this?
回答1:
You can add a pre-commit hook.
You can version in your git repo a hook script (say pre-commit.sh
) at the root of your project and include the installation instructions in your README/documentation
to encourage all developers use it.
Installation is nothing more than:
ln -s ../../pre-commit.sh .git/hooks/pre-commit
As the article "Tips for using a git pre-commit hook", you need, in that hook, to ensure that code that isn't part of the prospective commit isn't tested within your pre-commit script:
# pre-commit.sh
git stash -q --keep-index
# Test prospective commit
# call format, stylecop...
git stash pop -q
来源:https://stackoverflow.com/questions/26308076/version-control-over-visual-studio-formatting-style