Instructor: We have two branches here and we are currently on our master branch. Let's write a function like second function. That's just going to alert this is number two. Save that. If we do a git status, we have modified app JS, so let's add that and commit that as my second function.
Before pushing, we do a git branch and realize we made this change on the master branch and we meant to do it on the JS changes branch. If we do a git log --oneline now, we can see that we want to move this commit from master over to JS changes. The problem is master is pointing here. We have to be able to move master back here as well.
There are several ways we can do this. Many of them involve a git reset hard at some point. Beware of those because if you do reset hard incorrectly, you can lose data. We're going to use git reset, but not a git reset hard.
Let's look at our branches again. We're going to switch to the JS changes branch, so git checkout JS changes. What we want to do to get this function into it is copy this commit hash. We're going to cherry pick that commit hash. We're going to cherry pick the commit hash that we want to move over.
Now, on the JS changes branch, we have the code we want so we can push that. Now JS changes is correct. Let's switch back to master.
If we look at master, we still have the code here. If we do a log one line, we still have that commit because cherry pick just copies over the commit. It doesn't remove it from the other branch. What we want to do is switch master to be back at this commit.
We're going to do a git reset here, but not a reset hard, back to this commit hash. We could do that commit hash or we could go to the head and go back one. We'll do that. Now if we do a git status, we have app.js, which is still modified. This is because we didn't do a reset hard.
Now what we can do, since we don't want this function in here, is we can manually do this remediation, which is git checkout app.js. That will reset app.js to whatever it is at the hash that we reset to.
If we do a git status now, app.js is not changed. If we do a git log --oneline, that commit is gone. This is like manually doing a reset hard, but I like this better because we get to choose exactly what files we get to reset.