Instructor: We're in @.js here and let's make a function called hello world and that function is just going to alert hello. Then sometime later we close this file and open our index.html file and we're going to put a description in here. That will say, "Here's how to fix some common git mistakes."
What we want to do is commit just this index to html file, but if we're careless and we just do a Git Add-A without looking and we commit that, then we have Git Commit-M adds a description to index. Now if we do Git Status, we can see we're ahead by two commands.
Let's take a look at the log with git log, one line. What we want to do is undo this commit because this commit is the one with the mistake in it. To do that, we're going to use git reset. Git reset takes us back to where we want to reset to. There's two ways we could specify that.
We want to reset back to this commit here. We could say head and then go back one. That's head ~ 1 and that will go to head and then back on the 301 or we could say git reset and then we could copy this hash exactly so we know what we're resetting to. Now we have reset and we have unstaged changes.
If we do a git status, now it says we have these changes that are not staged for commit. It's like we didn't even commit them in the first place. For this reason, you really want to be careful. If we had pushed this commit already and then we reset it, then that means we are changing the history that other people may have already downloaded.
We only want to use reset on branches that we haven't pushed yet. Now, we could git add index.html, which is the only change we want to add and then double check with git status. We have the index to be committed and we are not committing app.js.
Now we can commit a description for index. If we do a git status now, we have app.js not staged for a commit. We are two commits ahead of origin/master. We can do git log --oneline now. We've gotten rid of that old commit. We are replacing it with this new one.