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.

  • Using Git to distribute nightly builds to a studio
  • Adding TortoiseSVN Context menus to Visual Studio Express
  • See git commands generated by TortoiseGit
  • LibGit2Sharp log remote
  • is there an API for GIT (C++ or other languages)
  • Auto Versioning with Git in Visual C++
  • 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.

  • Git Bash giving sh.exe: ruby: command not found
  • can't connect to github via ssh
  • Merge GIT branch without commit log
  • specifying git branch for remote
  • Large git push fails
  • Why should I use core.autocrlf=true in Git?
  • 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:
    REM  screenshot:!/tim_abell/status/199474387731226624/photo/1
    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 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.