Skip to content

lab 32 Resetting the Greet Branch

Goals

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:

git checkout greet
git hist

Output:

$ git checkout greet
Already on 'greet'
$ git hist
*   8c8444e 2018-09-28 | Merged master fixed conflict. (HEAD -> greet) [Jim Weirich]
|\  
| * 17a6c56 2018-09-28 | Made interactive (master) [Jim Weirich]
* |   2424440 2018-09-28 | Merge branch 'master' into greet [Jim Weirich]
|\ \  
| |/  
| * 5c40874 2018-09-28 | Added README [Jim Weirich]
* | 3f038a4 2018-09-28 | Updated Rakefile [Jim Weirich]
* | fa0b537 2018-09-28 | Hello uses Greeter [Jim Weirich]
* | 6f9af14 2018-09-28 | Added greeter class [Jim Weirich]
|/  
* 191f0c6 2018-09-28 | Added a Rakefile. [Jim Weirich]
* ef98cae 2018-09-28 | Moved hello.rb to lib [Jim Weirich]
* e1e08fd 2018-09-28 | Add an author/email comment [Jim Weirich]
* 7bf0bf1 2018-09-28 | Added a comment (tag: v1) [Jim Weirich]
* 9cf3f21 2018-09-28 | Added a default value (tag: v1-beta) [Jim Weirich]
* 94e1b8b 2018-09-28 | Using ARGV [Jim Weirich]
* f656098 2018-09-28 | 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 3f038a4
HEAD is now at 3f038a4 Updated Rakefile

Check the branch.

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
* 3f038a4 2018-09-28 | Updated Rakefile (HEAD -> greet) [Jim Weirich]
* fa0b537 2018-09-28 | Hello uses Greeter [Jim Weirich]
* 6f9af14 2018-09-28 | Added greeter class [Jim Weirich]
| * 17a6c56 2018-09-28 | Made interactive (master) [Jim Weirich]
| * 5c40874 2018-09-28 | Added README [Jim Weirich]
|/  
* 191f0c6 2018-09-28 | Added a Rakefile. [Jim Weirich]
* ef98cae 2018-09-28 | Moved hello.rb to lib [Jim Weirich]
* e1e08fd 2018-09-28 | Add an author/email comment [Jim Weirich]
* 7bf0bf1 2018-09-28 | Added a comment (tag: v1) [Jim Weirich]
* 9cf3f21 2018-09-28 | Added a default value (tag: v1-beta) [Jim Weirich]
* 94e1b8b 2018-09-28 | Using ARGV [Jim Weirich]
* f656098 2018-09-28 | First Commit [Jim Weirich]