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
*   50664fa 2019-11-01 | Merged master fixed conflict. (HEAD -> greet) [Jim Weirich]
|\  
| * fabda38 2019-11-01 | Made interactive (master) [Jim Weirich]
* |   69be050 2019-11-01 | Merge branch 'master' into greet [Jim Weirich]
|\ \  
| |/  
| * 099ccd0 2019-11-01 | Added README [Jim Weirich]
* | 69a8d70 2019-11-01 | Updated Rakefile [Jim Weirich]
* | 7b8b268 2019-11-01 | Hello uses Greeter [Jim Weirich]
* | f84663f 2019-11-01 | Added greeter class [Jim Weirich]
|/  
* ed35144 2019-11-01 | Added a Rakefile. [Jim Weirich]
* 4421854 2019-11-01 | Moved hello.rb to lib [Jim Weirich]
* 185fc95 2019-11-01 | Add an author/email comment [Jim Weirich]
* 4d578d4 2019-11-01 | Added a comment (tag: v1) [Jim Weirich]
* dc1d42f 2019-11-01 | Added a default value (tag: v1-beta) [Jim Weirich]
* 9a1c494 2019-11-01 | Using ARGV [Jim Weirich]
* 063b40e 2019-11-01 | 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 69a8d70
HEAD is now at 69a8d70 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
* 69a8d70 2019-11-01 | Updated Rakefile (HEAD -> greet) [Jim Weirich]
* 7b8b268 2019-11-01 | Hello uses Greeter [Jim Weirich]
* f84663f 2019-11-01 | Added greeter class [Jim Weirich]
| * fabda38 2019-11-01 | Made interactive (master) [Jim Weirich]
| * 099ccd0 2019-11-01 | Added README [Jim Weirich]
|/  
* ed35144 2019-11-01 | Added a Rakefile. [Jim Weirich]
* 4421854 2019-11-01 | Moved hello.rb to lib [Jim Weirich]
* 185fc95 2019-11-01 | Add an author/email comment [Jim Weirich]
* 4d578d4 2019-11-01 | Added a comment (tag: v1) [Jim Weirich]
* dc1d42f 2019-11-01 | Added a default value (tag: v1-beta) [Jim Weirich]
* 9a1c494 2019-11-01 | Using ARGV [Jim Weirich]
* 063b40e 2019-11-01 | First Commit [Jim Weirich]