1

I created a few commits in my local master. Before long I realized I should have setup a new branch and placed these commits there. I was easily able to setup a new branch which had all my commits.

What I need to address now is how to remove these commits from my local master branch.

I am thinking I would run "git reset --hard #lastHash" but I am worried about the behavior or running this on the master branch

Since I have not pushed or fetched any updates from orgin/master since I began making my own commits, will the hard reset only affect my local history? My concern is there are commits on origin/master that were created after I had starting making my own local commits

mrb398
  • 1,277
  • 4
  • 24
  • 32
  • if it's not a lot of changes, just recreate the repo and make a new branch – treyBake Nov 01 '18 at 15:16
  • Possible duplicates https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard, https://stackoverflow.com/questions/2530060/can-you-explain-what-git-reset-does-in-plain-english, and https://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state/1146981#1146981 – wspurgin Nov 01 '18 at 17:32

1 Answers1

3

git reset --hard <hash> will only change your local repository, unless you follow it up with a push.

  1. git checkout master
  2. git reset --hard <commit hash>

Where <commit hash> is the hash of the commit where you want the master branch. This will reset the current branch head to <commit hash>.

Bill
  • 1,407
  • 10
  • 18
  • 2
    In this specific situation, you could use `git reset --hard origin/master` and be sure your master will be push-able – OhleC Nov 01 '18 at 15:25