# Verify that all Git commits of a C# project compile after rewriting history

Is there any automated way to verify that all commits in a Git repo are in a compilable state?

I need this to verify I haven’t broken anything after rewriting history. Since I’m rewriting history, this excludes a build server – a commit that worked at the time it was committed might be broken after rewriting history.

• put build date in about box
• Building Boost dynamically linkable gives linking error?
• Putting git commit and git diff into binary as strings?
• AnkhSVN keeps marking .designer.cs files as newly added
• Deployment to Azure from Jenkins not working because of “A network-related or instance-specific error occurred” (Error 26)
• How to deal with development churn
• For example I have a Visual Studio 2015 C# project, and I imagine some script like:

git filter-branch --tree-filter msbuild


I want it to run a build on each commit, and stop with an error message if the build process returns nonzero.

• How to make Git as safe as possible for beginners?
• How to “git show” a merge commit with combined diff output even when every changed file agrees with one of the parents?
• Using Git With Eclipse Remote Systems Explorer
• Can we use :podspec link with dependencies in a podspec
• Cannot git diff. File exists in both branches but getting “fatal: Path '…' exists on disk, but not in 'master'”?
• git error - failed to push some refs (pack-objects died with strange error)
• ### 3 Solutions collect form web for “Verify that all Git commits of a C# project compile after rewriting history”

Considering the tree-filter will execute the command from a Git bash, you might want to use

git filter-branch --tree-filter "MSBuild.exe"


(making sure your %PATH% does include c:\Program Files (x86)\MSBuild\14.0\Bin)
(or use forward slash as in here)

That would be equally valid for the other option mentioned in the comments

git rebase -i --exec MSBuild.exe <first sha you want to test>~


You can use a CMD session similar to this gist, from Tim Abell:

@echo off
REM  batch script for loading git-bash and the vs tools in the same window
REM  inspiration: http://www.drrandom.org/post/2011/11/16/Grappling-with-multiple-remotes-in-git-tfs.aspx
%HOMEDRIVE%
cd %HOMEPATH%
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
echo Use full exe names when running under bash, e.g. "msbuild.exe"
echo Loading bash, you may now use git and msbuild in the same console \o/.
"C:\Program Files (x86)\Git\bin\sh.exe" --login -i


Assuming you want to check all the historical commits in the repo, not the future commits:

You can use git bisect to do that:

git bisect start
git bisect bad # Mark the current HEAD as bad
git bisect good <the first commit>


You then need a script that runs msbuild, returns 1 for build errors, and 125 for successful build. This is because we can’t mark any build as “good”, since we don’t know if the commits before this one also work, so instead we skip those that do work.

Then, start bisecting with the run command:

git bisect run myscript


This will then start running builds (in a non-consecutive order) until it finds a broken build, and stops. See https://git-scm.com/docs/git-bisect#_bisect_run for more explanation.

What about (tested on Git Bash and Git Posh):

1. Creating git alias for msbuild command:

git config --global --add alias.msbuild "!c:\path\to\msbuild.exe"

If “msbuild.exe” path is present in PATH env. var, you can just write “!msbuild” instead of a full path.

1. Then run the command:

git filter-branch --tree-filter "git msbuild"

Git Baby is a git and github fan, let's start git clone.