Neil G
Neil G

Reputation: 33242

How do I efficiently rewind and replay my changes in git?

I made the mistake of committing a large change (3k lines) my project, which is managed as a git repository. Most of my tests are broken, and I can't seem to figure out why. I would like to go back to an earlier to checkpoint, and replay my changes slowly. What's the most efficient way to do this?

I was thinking I could git reset to the earlier checkpoint and add the changes to a branch. And then what? Do I make changes and keep comparing the branch to master all along ensuring that my tests still pass as I make commits to master? Is there a better way?

Upvotes: 0

Views: 58

Answers (1)

matt
matt

Reputation: 535606

Ooooo, a perfect use for git bisect. It's pretty wonderful! Basically it does an orderly search through your commits, and for each one, you say whether the outcome is "bad" or "good". It takes the smallest possible number of steps (hence "bisect"). When you're done, it tells you where the "bad" got introduced. It's great when you or a colleague has introduced a bad side effect.

For this situation where you introduced the issue all at once, it does sound like you'd need to branch off an earlier commit and reproduce the "pieces" of the change as individual commits along that branch. That could be kind of a pain. But once you've done that, git bisect is the tool you are looking for.

Upvotes: 1

Related Questions