mrb398
mrb398

Reputation: 1317

Behavior of "git reset --hard"

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

Upvotes: 1

Views: 695

Answers (1)

Bill
Bill

Reputation: 1425

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>.

Upvotes: 3

Related Questions