How to Commit the code in git without adding the Commit Message?
Github or any git server which provides you to commit your code need a commit message or commit instruction to commit your code through git client or their respective consoles.
The most common way which IT industry uses to commit the code to repository like github is through git client CLI.
well it is obvious that whenever you want to merge your commit to codebase it needs to be reviewed to check if it’s according to standard or not or if there is any vulnerability.
In review there is a possibility that your code needs some further changes needs to be made and for that you need make new commit on the top of existing commit.
but what if your company or team policy allows you to have only one commit message.
well you might be having a questing why only one commit message? there is a reason for having a only one commit message it improve the log reading i.e it helps us to track the changes made by individual in single commit message.
There are different ways we can have the single commit message in our PR either at the time of commiting or if your squashing the multiple commits here we will going to discuss the first approach.
- suppose you are commiting your code for first time you will going to use the below command.
git commit -m '<commit message>'
2. now you need to need push these changes to repo
git push origin <branch-name>
or if the branch is not available in remove but only in local use below command
git branch --set-upstream-to origin/<branch-name>
above command is going to create a branch in remote then you can push the code to the created branch.
Commiting Code without adding commit message
now you need to add few extra lines of code in push commit without adding the commit message well very simple
execute the below command in git client cli
git commit --amend --no-edit
above command is going to commit your code without adding the commit message
next you need to push your changes to remote
git push -f
NOTE: remember you need to force push the changes to remote otherwise it will not work.
and that’s it you are ready to got.