This week I updated my SSG, adding two new features in different branches. Then, I successfully merged them into my master branch using git commands.
New Features
The first feature I updated is the optional command for generating the lang attribute on the root <html>
element. I simply added one more option for command line function as below example.
.option('l', {
alias: 'lang',
describe: 'lang attribute for html',
type: 'string',
required: false
})
The second feature I updated is a horizontal rule in Markdown. So, ---
in the markdown file should be converted to <hr>
tag. I added a if-statement for ---
inside of the if-statement when file type is markdown. The code block looks like this.
else if(e === '---')
html += `<hr>${deli}`;
I know these new features are considerably easy, but I ran into some issues when splitting the sentences. The problem was new line comes out differently depending on what system you use, like window32, ubuntu, etc. So, I changed few lines for the delimiters, something like this.
const deli = process.platform === 'win32' ? '\r\n' : '\n';
Instead of using
let resArr = res.split(/n/n);
I use
let resArr = res.split(deli);
As a result, all the extra <p>
tags are gone, and the output looks good!
Git merge and branch
I have experience with this git feature. In one of my other classes, we submitted our assignments through git. My professor briefly explained how the git works and encouraged us to use a branch to avoid unrestorable updates and changes.
Making branches and working in that specific branches was the same process as I have been doing. The command is,
$ git checkout -b [branch name]
And it means making a branch that's named [branch name] and going into that branch.
However, I made an extra commit, but I wanted to remove it. Because it could give me confusion about which commit is new or what I want, and I only need one. How I solved this problem was the reset command.
If you enter:
$ git log
It shows you a history of everything that happened to the repository. You can see there are hash codes for your commit. So, I copied that and entered:
$ git reset [hash code]
Then, I could finally add my new files again, go to the master branch, and merge my branches. The command is :
$ git merge [branch name]
Even though I edited the same file, index.js, the parts that I touched in each branch were different. So, I didn't get any errors, but it can give you an error message if it is overlapped. So, be aware of that!
I am glad that I am understanding and learning about git. I know there must be more good features about git, and I can't wait to learn and use them!
Top comments (0)