Skip to content

lab 36 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 main 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 main. 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
*   8e3d2b5 2022-10-24 | Merged main fixed conflict. (HEAD -> greet) [Jim Weirich]
|\  
| * 06325a5 2022-10-24 | Made interactive (main) [Jim Weirich]
* | 5e8ac5c 2022-10-24 | Add some suspicion [Jim Weirich]
* | 71425e9 2022-10-24 | Add excitement (excitement) [Jim Weirich]
* | b1df40e 2022-10-24 | Merge branch 'main' into greet [Jim Weirich]
|\| 
| * 62f7394 2022-10-24 | Added README [Jim Weirich]
* | 18e7dbd 2022-10-24 | Updated Rakefile [Jim Weirich]
* | 2a024f1 2022-10-24 | Hello uses Greeter [Jim Weirich]
* | 85316c2 2022-10-24 | Added greeter class [Jim Weirich]
|/  
* 0022837 2022-10-24 | Added a Rakefile. [Jim Weirich]
* 3172288 2022-10-24 | Moved hello.rb to lib [Jim Weirich]
* 3e56dbf 2022-10-24 | Add an author/email comment [Jim Weirich]
* 1dee7f9 2022-10-24 | Tell user how many names they have (tag: v1) [Jim Weirich]
* c72af6b 2022-10-24 | Rename variable to match its usage (tag: v1-beta) [Jim Weirich]
* 8cdd2cd 2022-10-24 | Can specify multiple names [Jim Weirich]
* 28fe396 2022-10-24 | Added a comment [Jim Weirich]
* 15c7573 2022-10-24 | Added a default value [Jim Weirich]
* 7d55044 2022-10-24 | Using ARGV [Jim Weirich]
* 91b926e 2022-10-24 | 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 18e7dbd
HEAD is now at 18e7dbd 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
* 71425e9 2022-10-24 | Add excitement (excitement) [Jim Weirich]
*   b1df40e 2022-10-24 | Merge branch 'main' into greet [Jim Weirich]
|\  
* | 18e7dbd 2022-10-24 | Updated Rakefile (HEAD -> greet) [Jim Weirich]
* | 2a024f1 2022-10-24 | Hello uses Greeter [Jim Weirich]
* | 85316c2 2022-10-24 | Added greeter class [Jim Weirich]
| | * 06325a5 2022-10-24 | Made interactive (main) [Jim Weirich]
| |/  
| * 62f7394 2022-10-24 | Added README [Jim Weirich]
|/  
* 0022837 2022-10-24 | Added a Rakefile. [Jim Weirich]
* 3172288 2022-10-24 | Moved hello.rb to lib [Jim Weirich]
* 3e56dbf 2022-10-24 | Add an author/email comment [Jim Weirich]
* 1dee7f9 2022-10-24 | Tell user how many names they have (tag: v1) [Jim Weirich]
* c72af6b 2022-10-24 | Rename variable to match its usage (tag: v1-beta) [Jim Weirich]
* 8cdd2cd 2022-10-24 | Can specify multiple names [Jim Weirich]
* 28fe396 2022-10-24 | Added a comment [Jim Weirich]
* 15c7573 2022-10-24 | Added a default value [Jim Weirich]
* 7d55044 2022-10-24 | Using ARGV [Jim Weirich]
* 91b926e 2022-10-24 | First Commit [Jim Weirich]