Skip to content

lab 30 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
*   ca11819 2019-06-27 | Merged main fixed conflict. (HEAD -> greet) [Halle Bot]
|\  
| * 3c663d0 2019-06-27 | Made interactive (main) [Halle Bot]
* |   8c53c97 2019-06-27 | Merge branch 'main' into greet [Halle Bot]
|\ \  
| |/  
| * 3aa3064 2019-06-27 | Added README [Halle Bot]
* | f52644d 2019-06-27 | Updated package [Halle Bot]
* | 455c54f 2019-06-27 | Hello uses Greeter [Halle Bot]
* | 4fb8bde 2019-06-27 | Added greeter class [Halle Bot]
|/  
* 2b04803 2019-06-27 | Added a package.json. [Halle Bot]
* b65b430 2019-06-27 | Moved hello.js to lib [Halle Bot]
* 4535421 2019-06-27 | Add an author/email comment [Halle Bot]
* 59992ce 2019-06-27 | Added a comment (tag: v1) [Halle Bot]
* 20a6c79 2019-06-27 | Added a default value (tag: v1-beta) [Halle Bot]
* 6915d41 2019-06-27 | Using process.argv [Halle Bot]
* 284070d 2019-06-27 | First Commit [Halle Bot]

That’s a bit hard to read, but looking at the data we see that the “Updated package.json” 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 f52644d
HEAD is now at f52644d Updated package

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
* 3c663d0 2019-06-27 | Made interactive (main) [Halle Bot]
* 3aa3064 2019-06-27 | Added README [Halle Bot]
| * f52644d 2019-06-27 | Updated package (HEAD -> greet) [Halle Bot]
| * 455c54f 2019-06-27 | Hello uses Greeter [Halle Bot]
| * 4fb8bde 2019-06-27 | Added greeter class [Halle Bot]
|/  
* 2b04803 2019-06-27 | Added a package.json. [Halle Bot]
* b65b430 2019-06-27 | Moved hello.js to lib [Halle Bot]
* 4535421 2019-06-27 | Add an author/email comment [Halle Bot]
* 59992ce 2019-06-27 | Added a comment (tag: v1) [Halle Bot]
* 20a6c79 2019-06-27 | Added a default value (tag: v1-beta) [Halle Bot]
* 6915d41 2019-06-27 | Using process.argv [Halle Bot]
* 284070d 2019-06-27 | First Commit [Halle Bot]