I am trying to go back to a specific commit in Github to erase the mistake I made

Viewed 30

I have looked at many past posts without a specific response. I used git reset --hard to get me to a point in time when my code was not all jacked up. Yes I should have used a branch but I didn't. Now I have a message of HEAD is now at 0600b73 fixed error. What I would like to know is how to commit those changes, so I can push them back to Git, so they are the current head? I am not even sure if VS Code even recorded the changes. Git can be confusing so any help would be appreciated.

1 Answers

You haven't actually proven you have changes, HEAD is now at 0600b73 fixed error., that does not mean you have changes. That basically means that you moved the HEAD of git to a commit, generally you want it on a branch.

git status will tell you if you have things that need to be committed.

I am not even sure if VS Code even recorded the changes

VScode has some cool features around git but it doesn't actually record changes, unless you are referring to saving files. If you save the file, well it saves.

What you probably want to do is (I am assuming you actually do have changes):

  • confirm you have changes git status
  • move to a branch git checkout -b my-fix
  • add those changes git add . (adds all changes/also make sure you are at the root of the repo) or git add -p will let you look closely at changes and give you an interface to decide if you want to stage the change or not.
  • commit the changes git commit -m "Your message" or you can do a longer message with git commit -p

At this point you can merge this branch in to master, push the branch. It's up to you.

  • push your changes, git push origin my-fix, make a pull request and merge to master. You will then want to change to master and pull master
  • merge git checkout master , git merge my-fix
  • rebase git checkout master , git rebase my-fix

Here is some git learning material:

Related