Amending
If you check in a change and then realize you've left out a file or have mangled the message, you can use the amend
command. However, you can only amend the most recent commit.
Let's say we return to person and we add a weight property and then commit it. Before we push it, we realize we left out a change to Program.cs
:
namespace Rebasing
{
class Program
{
static void Main(string[] args)
{
var person = new Person();
person.Name = "Jesse";
}
}
}
Since the error was in the most recent commit, we can amend that commit. All we need to do is put the Program.cs
file into the index and then issue the command git commit --amend
.
Because amend rewrites history, you must do this only before you push (that is, while the commit is only in your local repo), for the same reasons as noted above:
Figure 5.10: Amending (before pushing!)
Let's take this one line at a time from...