One of the commits on master introduced a bad file.
Find the commit and revert it using bisect.
- Run
source setup.sh(or.\setup.ps1in PowerShell)
Use git bisect to find the "bad" commit and then use git revert to revert it. When running git bisect, you indicate if the "state" is "good" or "bad" until it finds the commit that introduced the change.
For this exercise, the version is bad if badfile exists.
- Start
git bisect. - Usually the HEAD is "bad", as it is in this exercise. Use
git bisect badto indicate it. - Usually some old version will be good. In this exercise, the start version is. Use
git bisect good <commit-ish>to indicate it. git bisectwill then checkout various commits to find the bad commit. Continue indicating the state until it tells you the first bad commit. Keep track of this commit.- Run
git bisect resetso we can work on the repository. - Use
git diffto make sure that the bad commit only introducedbadfile. - Use
git revertto it.
If you have a script that can tell if the current source code is good or bad, you can bisect by issuing git bisect run.
git bisect startgit bisect badgit bisect good <commit-ish>git bisect goodgit bisect resetgit diff <commit-ish-1> <commit-ish-2>git revert <commit-ish>git bisect run <cmd>test ! -f badfile(orgci . badfilein PowerShell) to test the existence of a filetest ! -f badfile;echo $?to output the result of the test to the console