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
*   419197d 2020-05-30 | Merged master fixed conflict. (HEAD -> greet) [Jim Weirich]
|\  
| * 6ec0242 2020-05-30 | Made interactive (master) [Jim Weirich]
* |   19cb822 2020-05-30 | Merge branch 'master' into greet [Jim Weirich]
|\ \  
| |/  
| * 32cb785 2020-05-30 | Added README [Jim Weirich]
* | 4721c3f 2020-05-30 | Updated Rakefile [Jim Weirich]
* | 4689e1b 2020-05-30 | Hello uses Greeter [Jim Weirich]
* | e685fb0 2020-05-30 | Added greeter class [Jim Weirich]
|/  
* 128a484 2020-05-30 | Added a Rakefile. [Jim Weirich]
* a3cf03d 2020-05-30 | Moved hello.rb to lib [Jim Weirich]
* 96c1fec 2020-05-30 | Add an author/email comment [Jim Weirich]
* 9811d9e 2020-05-30 | Added a comment (tag: v1) [Jim Weirich]
* 3344f03 2020-05-30 | Added a default value (tag: v1-beta) [Jim Weirich]
* 3cb4c15 2020-05-30 | Using ARGV [Jim Weirich]
* dfb5614 2020-05-30 | 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 4721c3f
HEAD is now at 4721c3f 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
* 6ec0242 2020-05-30 | Made interactive (master) [Jim Weirich]
* 32cb785 2020-05-30 | Added README [Jim Weirich]
| * 4721c3f 2020-05-30 | Updated Rakefile (HEAD -> greet) [Jim Weirich]
| * 4689e1b 2020-05-30 | Hello uses Greeter [Jim Weirich]
| * e685fb0 2020-05-30 | Added greeter class [Jim Weirich]
|/  
* 128a484 2020-05-30 | Added a Rakefile. [Jim Weirich]
* a3cf03d 2020-05-30 | Moved hello.rb to lib [Jim Weirich]
* 96c1fec 2020-05-30 | Add an author/email comment [Jim Weirich]
* 9811d9e 2020-05-30 | Added a comment (tag: v1) [Jim Weirich]
* 3344f03 2020-05-30 | Added a default value (tag: v1-beta) [Jim Weirich]
* 3cb4c15 2020-05-30 | Using ARGV [Jim Weirich]
* dfb5614 2020-05-30 | First Commit [Jim Weirich]