The easiest way to integrate the branches, as we’ve already covered, is themerge
command. It performs a three-way merge between the two latest branch snapshots and the most recent common ancestor of the two , creating a new snapshot (and commit).
However, there is another way: you can take the patch of the change that was introduced on one branch and reapply it on top of another branch. In Git, this is called rebasing. With the rebase command, you can take all the changes that were committed on one branch and replay them on a different branch.
In the blog, I continued working on myrepo, a static site generator (SSG) writing with Python. It started with working on a new branchgit checkout -b refactoring
, and the goal is to improve the structure and maintainability of the code without altering its behaviour. The main funtionality of this SSG has already been encapsulated in a classGenerator
, and this class was called in themain()
function. Therefore, I was trying to polish the code with variables rename, making code style consistent and rewriting the support ofconfig
file functionality, which was wrote by other contributors.
The original support ofconfig
file functionality was achieved by usingjson
parser. However, there are several packages published to support the command line config file. Here, theclick_config_file
module was used to support configuration file. In this way, themain()
function was simlified a lot by replacing the json parser and reading json file line by line code part with a single function decorator (function annotation).
Moreover, the code style was improved on several places. For instance,inp != None
was changed toinp is not None
and several indentations were fixed.
Finally, an exampleconfig
file was added.
Now, with several commits, we can use the terminal commandgit rebase main -i
. This open an interactive window. Then, we cansquash
all commits into the first one. Additionaly, if there is a need, usegit --amend
to edit commit message.
Eventually, merge to main use:
git checkout maingit merge refactoringgit push origin main
The combined commit can be foundhere.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse