lab 32 Resetting the Greet Branch
Goals
- Reset the greet branch to the point before the first merge.
Reset the greet branch 01
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:
git checkout greet git hist
Output:
$ git checkout greet Already on 'greet' $ git hist * 25f0e8c 2013-04-13 | Merged master fixed conflict. (HEAD, greet) [Jim Weirich] |\ | * 05f32c0 2013-04-13 | Made interactive (master) [Jim Weirich] * | 844d1ed 2013-04-13 | Merge branch 'master' into greet [Jim Weirich] |\ \ | |/ | * b59a8c2 2013-04-13 | Added README [Jim Weirich] * | 28917a4 2013-04-13 | Updated Rakefile [Jim Weirich] * | 4dac415 2013-04-13 | Hello uses Greeter [Jim Weirich] * | 39347b3 2013-04-13 | Added greeter class [Jim Weirich] |/ * 96ee164 2013-04-13 | Added a Rakefile. [Jim Weirich] * 0f36766 2013-04-13 | Moved hello.rb to lib [Jim Weirich] * eb30103 2013-04-13 | Add an author/email comment [Jim Weirich] * 1f7ec5e 2013-04-13 | Added a comment (v1) [Jim Weirich] * 582495a 2013-04-13 | Added a default value (v1-beta) [Jim Weirich] * 323e28d 2013-04-13 | Using ARGV [Jim Weirich] * 9416416 2013-04-13 | 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.
NOTE: Replace <hash> with the actual hash of the relevant commit.
Execute:
git reset --hard <hash>
Output:
$ git reset --hard 28917a4 HEAD is now at 28917a4 Updated Rakefile
Check the branch. 02
Look at the log for the greet branch. We no longer have the merge commits in its history.
Execute:
git hist --all
Output:
$ git hist --all * 05f32c0 2013-04-13 | Made interactive (master) [Jim Weirich] * b59a8c2 2013-04-13 | Added README [Jim Weirich] | * 28917a4 2013-04-13 | Updated Rakefile (HEAD, greet) [Jim Weirich] | * 4dac415 2013-04-13 | Hello uses Greeter [Jim Weirich] | * 39347b3 2013-04-13 | Added greeter class [Jim Weirich] |/ * 96ee164 2013-04-13 | Added a Rakefile. [Jim Weirich] * 0f36766 2013-04-13 | Moved hello.rb to lib [Jim Weirich] * eb30103 2013-04-13 | Add an author/email comment [Jim Weirich] * 1f7ec5e 2013-04-13 | Added a comment (v1) [Jim Weirich] * 582495a 2013-04-13 | Added a default value (v1-beta) [Jim Weirich] * 323e28d 2013-04-13 | Using ARGV [Jim Weirich] * 9416416 2013-04-13 | First Commit [Jim Weirich]