lab 29 Resetting the Greet Branch
Goals
- Reset the greet branch to the point before the first merge.
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 * e118dc5 2023-08-21 | Merged main fixed conflict. (HEAD -> greet) [Théophile Chevalier] |\ | * b74b20e 2023-08-21 | Made interactive (main) [Théophile Chevalier] * | 33134b5 2023-08-21 | Merge branch 'main' into greet [Théophile Chevalier] |\| | * 6179ba3 2023-08-21 | Added README [Théophile Chevalier] * | cc98109 2023-08-21 | Hello uses Greeter [Théophile Chevalier] * | d6aae18 2023-08-21 | Add greeter class [Théophile Chevalier] |/ * 9ab61ca 2023-08-21 | Moved hello.py to lib [Théophile Chevalier] * 7abea37 2023-08-21 | Add an author/email comment [Théophile Chevalier] * 1c410c6 2023-08-21 | Add a comment (tag: v1) [Théophile Chevalier] * 0bf384c 2023-08-21 | Display user input (tag: v1-beta) [Théophile Chevalier] * 31c3945 2023-08-21 | Add some content [Théophile Chevalier] * aa5d425 2023-08-21 | First Commit [Théophile Chevalier]
That’s a bit hard to read, but looking at the data we see that the “Hello uses Greeter” 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 cc98109 HEAD is now at cc98109 Hello uses Greeter
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 * b74b20e 2023-08-21 | Made interactive (main) [Théophile Chevalier] * 6179ba3 2023-08-21 | Added README [Théophile Chevalier] | * cc98109 2023-08-21 | Hello uses Greeter (HEAD -> greet) [Théophile Chevalier] | * d6aae18 2023-08-21 | Add greeter class [Théophile Chevalier] |/ * 9ab61ca 2023-08-21 | Moved hello.py to lib [Théophile Chevalier] * 7abea37 2023-08-21 | Add an author/email comment [Théophile Chevalier] * 1c410c6 2023-08-21 | Add a comment (tag: v1) [Théophile Chevalier] * 0bf384c 2023-08-21 | Display user input (tag: v1-beta) [Théophile Chevalier] * 31c3945 2023-08-21 | Add some content [Théophile Chevalier] * aa5d425 2023-08-21 | First Commit [Théophile Chevalier]