You committed your work to the repository and just realized that you’ve forgotten to include some of the files. Let’s see how we can fix that by leveraging git --amend
to include the missing files as well.
Note: This only holds if you did not yet push your changes to the remote repository
Instructor: [00:00] In my repository here, I have added a new Angular component, which is that shared folder here, which I've added to that shared module. I am just adding all of this, and I am committing it. If I take a look at the log, we can see that we have added the commit here on top of master.
[00:19] Now, I forgot to add that app folder component, which I just created also in my app component. Let's jump over to the editor and correct that. In the editor here, I'm opening up that app component. Rather than having here the folder, I'm now using the new component I just created.
[00:33] Back in our terminal, we can see here the modified file. What I would like to have is, of course, add this to that last commit, to add new app folder. It makes sense to have that included in there. That is already committed, however.
[00:48] What I can do is I can use the git commit amend command. First of all, I am adding my app folder to the staging area. Now, it's ready to be committed. Now, I do a git commit, and I add that amend. If I hit enter, will open up the editor again.
[01:08] We now see that we got that modified file included in our commit changes as well. We can leave the message as it is. I'm just saving. Now, if I do a git log, we can see that the commit message is still here. It didn't change, but our app component modification has been integrated in that last commit.