I am very new to Github. I am trying to fix a typo in a Javascript file. I have created a separate branch, added the file but I'm not sure exactly how to amend the typo here. This just gives me an unrelated histories error and I'm just a bit confused about how to correct this file:
// Constants
const PORT = 8001;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello, Wrld');
});
app.listen(PORT, HOST);
console.log(); '''
This is what I've done so far.
to say "Hello World" instead of "Hello, World"
git branch fix_typo
git checkout fix_typo
git add server.js
cat server.js
echo “Hello, World” > server.j
git add server.js
git commit --amend -m "Hello, World Fix Typo"
git checkout master
git merge fix_typo
git push origin fix_typo
I also wanted to ask how would I go about changing the port on this file?
You don't need to add the file to the new branch. When you make a branch, it copies all the files from the current branch.
You shouldn't just echo "Hello, World" to the file, you need to edit the file to keep all the other lines. You can use sed for this, and you can use multiple -e options to perform multiple substitutions.
git branch fix_typo
git checkout fix_typo
sed -i -e 's/Hello, Wrld/Hello, World/' -e 's/PORT = 8001/PORT = 80/' server.js
git commit -m "Hello, World Fix Typo"
git push
git checkout master
git merge fix_typo
git push origin