lab 32 Resetting the Greet Branch

Goals

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
*   885ca6f 2014-10-25 | Merged master fixed conflict. (HEAD, greet) [Jim Weirich]
|\  
| * 8697f14 2014-10-25 | Made interactive (master) [Jim Weirich]
* |   9d0aceb 2014-10-25 | Merge branch 'master' into greet [Jim Weirich]
|\ \  
| |/  
| * 6fd9eff 2014-10-25 | Added README [Jim Weirich]
* | 12414e9 2014-10-25 | Updated Rakefile [Jim Weirich]
* | 43ba308 2014-10-25 | Hello uses Greeter [Jim Weirich]
* | acd8535 2014-10-25 | Added greeter class [Jim Weirich]
|/  
* 14ba469 2014-10-25 | Added a Rakefile. [Jim Weirich]
* 4b249b3 2014-10-25 | Moved hello.rb to lib [Jim Weirich]
* bfd1408 2014-10-25 | Add an author/email comment [Jim Weirich]
* a1189df 2014-10-25 | Added a comment (tag: v1) [Jim Weirich]
* 6083cb8 2014-10-25 | Added a default value (tag: v1-beta) [Jim Weirich]
* b24f3ff 2014-10-25 | Using ARGV [Jim Weirich]
* cf466b4 2014-10-25 | 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:

git reset --hard <hash>

Output:

$ git reset --hard 12414e9
HEAD is now at 12414e9 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
* 12414e9 2014-10-25 | Updated Rakefile (HEAD, greet) [Jim Weirich]
* 43ba308 2014-10-25 | Hello uses Greeter [Jim Weirich]
* acd8535 2014-10-25 | Added greeter class [Jim Weirich]
| * 8697f14 2014-10-25 | Made interactive (master) [Jim Weirich]
| * 6fd9eff 2014-10-25 | Added README [Jim Weirich]
|/  
* 14ba469 2014-10-25 | Added a Rakefile. [Jim Weirich]
* 4b249b3 2014-10-25 | Moved hello.rb to lib [Jim Weirich]
* bfd1408 2014-10-25 | Add an author/email comment [Jim Weirich]
* a1189df 2014-10-25 | Added a comment (tag: v1) [Jim Weirich]
* 6083cb8 2014-10-25 | Added a default value (tag: v1-beta) [Jim Weirich]
* b24f3ff 2014-10-25 | Using ARGV [Jim Weirich]
* cf466b4 2014-10-25 | First Commit [Jim Weirich]

Table of Contents