Resetting the Greet Branch

Goals

  • Reset the greet branch to the point before the first merge.

Reset the greet branch

Let’s go back in time on the greet branch to the point before we merged master onto it. We can reset a branch to any commit we want. Essentially this is modifying the branch pointer to point to anywhere in the commit tree.

In this case we want to back greet up to the point prior to the merge with master. We need to find the last commit before the merge.

Execute:

  1. git checkout greet
  2. git hist

Output:

  1. $ git checkout greet
  2. Already on 'greet'
  3. $ git hist
  4. * 6938117 2020-06-20 | Merged master fixed conflict. (HEAD -> greet) [Jim Weirich]
  5. |\
  6. | * ee97f8e 2020-06-20 | Made interactive (master) [Jim Weirich]
  7. * | a87176d 2020-06-20 | Merge branch 'master' into greet [Jim Weirich]
  8. |\ \
  9. | |/
  10. | * 8d90176 2020-06-20 | Added README [Jim Weirich]
  11. * | 228a31e 2020-06-20 | Updated Rakefile [Jim Weirich]
  12. * | 98cfd8a 2020-06-20 | Hello uses Greeter [Jim Weirich]
  13. * | cf0438b 2020-06-20 | Added greeter class [Jim Weirich]
  14. |/
  15. * 5aec14d 2020-06-20 | Added a Rakefile. [Jim Weirich]
  16. * 721b979 2020-06-20 | Moved hello.rb to lib [Jim Weirich]
  17. * 907a445 2020-06-20 | Add an author/email comment [Jim Weirich]
  18. * 4254c94 2020-06-20 | Added a comment (tag: v1) [Jim Weirich]
  19. * c8b3af1 2020-06-20 | Added a default value (tag: v1-beta) [Jim Weirich]
  20. * 30c2cd4 2020-06-20 | Using ARGV [Jim Weirich]
  21. * 4445720 2020-06-20 | First Commit [Jim Weirich]

That’s a bit hard to read, but looking at the data we see that the “Updated Rakefile” commit was the last commit on the greet branch before merging. Let’s reset the greet branch to that commit.

Execute:

  1. git reset --hard <hash>

Output:

  1. $ git reset --hard 228a31e
  2. HEAD is now at 228a31e Updated Rakefile

Check the branch.

Look at the log for the greet branch. We no longer have the merge commits in its history.

Execute:

  1. git hist --all

Output:

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