27. Resetting the style
branch
Goals
- Reset the branch
style
to the point before the first merge withmain
.
01 Resetting the style
branch
Let us go to the style
branch to the point before we had merged it with the main
branch. We can reset
the branch to any commit. In fact, the reset
command can change the branch pointer to point to any commit in the tree.
Here, we want to go back in the style
branch to a point before merging with the main
. We have to find the last commit before the merge.
Run
git switch style
git log --graph
Result
$ git switch style
Already on 'style'
$ git log --graph
* 79ac6fa 2023-11-28 | Resolved merge conflict (HEAD -> style) [Alexander Shvets]
|\
| * 85c14e9 2023-11-28 | Added meta title (main) [Alexander Shvets]
* | a33deed 2023-11-28 | Merge branch 'main' into style [Alexander Shvets]
|\|
| * ee16740 2023-11-28 | Added README [Alexander Shvets]
* | 0ee0113 2023-11-28 | Renamed hello.html; moved style.css [Alexander Shvets]
* | 903eb1d 2023-11-28 | Included stylesheet into hello.html [Alexander Shvets]
* | 555372e 2023-11-28 | Added css stylesheet [Alexander Shvets]
|/
* 9288a33 2023-11-28 | Added copyright statement with email [Alexander Shvets]
* b7614c1 2023-11-28 | Added HTML header (tag: v1) [Alexander Shvets]
* 46afaff 2023-11-28 | Added standard HTML page tags (tag: v1-beta) [Alexander Shvets]
* 78433de 2023-11-28 | Added h1 tag [Alexander Shvets]
* 5836970 2023-11-28 | Initial commit [Alexander Shvets]
It's a little hard to read, but we can see from the output that the "Renamed hello.html; moved style.css" commit was the latest on the style
branch prior to the first merging with main
. Let us reset the style
branch to this commit. To reference that commit, we either use its hash, or deduct that this commit is 2 commits before the HEAD
, or HEAD~2
in Git notation.
Run
git reset --hard HEAD~2
Result
$ git reset --hard HEAD~2
HEAD is now at 0ee0113 Renamed hello.html; moved style.css
02 Check the branch
Now, lets check the log of the style
branch. There should be no merge commits in the log.
Run
git log --graph
Result
$ git log --graph
* 0ee0113 2023-11-28 | Renamed hello.html; moved style.css (HEAD -> style) [Alexander Shvets]
* 903eb1d 2023-11-28 | Included stylesheet into hello.html [Alexander Shvets]
* 555372e 2023-11-28 | Added css stylesheet [Alexander Shvets]
* 9288a33 2023-11-28 | Added copyright statement with email [Alexander Shvets]
* b7614c1 2023-11-28 | Added HTML header (tag: v1) [Alexander Shvets]
* 46afaff 2023-11-28 | Added standard HTML page tags (tag: v1-beta) [Alexander Shvets]
* 78433de 2023-11-28 | Added h1 tag [Alexander Shvets]
* 5836970 2023-11-28 | Initial commit [Alexander Shvets]