Resetting the Master Branch

Goals

  • Reset the master branch to the point before the conflicting commit.

Reset the master branch

When we added the interactive mode to the master branch, we made a change that conflicted with changes in the greet branch. Let’s rewind the master branch to a point before the conflicting change. This allows us to demonstrate the rebase command without worrying about conflicts.

Execute:

  1. git checkout master
  2. git hist

Output:

  1. $ git hist
  2. * ee97f8e 2020-06-20 | Made interactive (HEAD -> master) [Jim Weirich]
  3. * 8d90176 2020-06-20 | Added README [Jim Weirich]
  4. * 5aec14d 2020-06-20 | Added a Rakefile. [Jim Weirich]
  5. * 721b979 2020-06-20 | Moved hello.rb to lib [Jim Weirich]
  6. * 907a445 2020-06-20 | Add an author/email comment [Jim Weirich]
  7. * 4254c94 2020-06-20 | Added a comment (tag: v1) [Jim Weirich]
  8. * c8b3af1 2020-06-20 | Added a default value (tag: v1-beta) [Jim Weirich]
  9. * 30c2cd4 2020-06-20 | Using ARGV [Jim Weirich]
  10. * 4445720 2020-06-20 | First Commit [Jim Weirich]

The ‘Added README’ commit is the one directly before the conflicting interactive mode. We will reset the master branch to ‘Added README’ commit.

Execute:

  1. git reset --hard <hash>
  2. git hist --all

Review the log. It should look like the repository has been wound back in time to the point before we merged anything.

Output:

  1. $ git hist --all
  2. * 8d90176 2020-06-20 | Added README (HEAD -> master) [Jim Weirich]
  3. | * 228a31e 2020-06-20 | Updated Rakefile (greet) [Jim Weirich]
  4. | * 98cfd8a 2020-06-20 | Hello uses Greeter [Jim Weirich]
  5. | * cf0438b 2020-06-20 | Added greeter class [Jim Weirich]
  6. |/
  7. * 5aec14d 2020-06-20 | Added a Rakefile. [Jim Weirich]
  8. * 721b979 2020-06-20 | Moved hello.rb to lib [Jim Weirich]
  9. * 907a445 2020-06-20 | Add an author/email comment [Jim Weirich]
  10. * 4254c94 2020-06-20 | Added a comment (tag: v1) [Jim Weirich]
  11. * c8b3af1 2020-06-20 | Added a default value (tag: v1-beta) [Jim Weirich]
  12. * 30c2cd4 2020-06-20 | Using ARGV [Jim Weirich]
  13. * 4445720 2020-06-20 | First Commit [Jim Weirich]