6

I use Git for source control and build with Visual Studio 2008. Mostly I build on one branch (master). Often I need to do a code review and switch to another branch (develop) temporarily. I do not build code that I review and after review is finished I switch back to the original branch:

  1. develop on master
  2. commit everything (branch is clean)
  3. build
  4. switch to develop
  5. do code review
  6. switch to master
  7. continue to develop on master
  8. build (recompiles many files, not only ones modified in previous step)

If master and develop have different versions of one file, the modification date and time for that file are updated to the moment of checkout after switching branches in step 5. This causes Visual Studio to rebuild them in the step 8 despite the fact that souce code have not changed.

How can I avoid massive rebuilds when changing branches?

Sergiy Belozorov
  • 5,856
  • 7
  • 40
  • 73
  • There is a good discussion about it here: https://stackoverflow.com/questions/10356165/avoid-recompilation-with-git-and-make – Marcio Jun 04 '19 at 13:09

3 Answers3

3

As a workaround, it might be useful for you to do code reviews in a different clone from your development clone. That way, switching to a review branch won't change the files in your master clone, which won't cause VS to unnecessarily rebuild them.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
1

You could script a checkout of just the differring files. So don't do a real checkout but alter the working directory to look like the other branch.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
0

git worktree works. It let you work on multi-branches and without switching.

yue huang
  • 1
  • 1