How does Git backtracking differ from simply commiting the desired changes?


#1

Question

In the lessons on Git backtracking, we’re introduced to techniques for modifying a previous commit. How does this differ from making a commit with the corrections?

Answer

Backtracking differs in a few ways from making a new commit but there are two reasons that are important for up at this point. First, by backtracking instead of making new commits, we’re able to make small changes to our previous commits without cluttering our repository history with commit messages of similar to “forgot to add file X from my previous commit so doing that now.” Second, and very important, is the following (to quote ProGit):

It’s important to understand that when you’re amending your last commit, you’re not so much fixing it as replacing it entirely with a new, improved commit that pushes the old commit out of the way and puts the new commit in its place. Effectively, it’s as if the previous commit never happened, and it won’t show up in your repository history.

As you should see now, backtracking behaves differently from committing and serve different purposes.


FAQ: How to Backtrack - Backtracking Intro