This tutorial will demonstrate the method to use the Git editor of choice for editing commit messages.
How to Use the Git Editor of Choice For Editing Commit Messages in Git
The default Git editor is selected during the Git installation. On the other hand, users can utilize the editor of their choice for editing Git commit messages, files, and many more.
To edit the commit message using your preferred Git editor, follow up on the mentioned instructions.
Step 1: Open Git Bash Terminal
Open the Git Bash terminal from the Start menu:
Step 2: Open Git Repository
Open the Git repository using the βcdβ command:
Step 3: Generate New File
Utilize the βtouchβ command to generate a new file:
Step 4: Add Untracked Changes to Tracking Index
After that, add the untracked file to the tracking index by executing the below command:
Check out the βgit statusβ command to verify if the changes are added to the tracking index or not:
You can see we have successfully added the file to the staging area:
Step 5: Commit Tracked Changes
Commit the tracked changes using the βgit commitβ command. Here, the option β–amendβ is used to edit a commit in the default selected editor:
It can be observed that the βNotepadβ is opened by default to edit commits. Edit your message as we have edited βDemo file is savedβ:
Step 6: Check Git Log
List down the Git repository log using the βgit logβ command to verify if the commit is added or not:
It can be observed that we have successfully committed the tracked changes:
Step 7: Change Editor
Now, set the editor of your choice to edit the commit message. For instance, we have selected the βnanoβ editor:
Step 8: Edit Commit Message in Your Preferred Editor
Again, use the βgit commit –amendβ command to modify the Git commit message in your preferred editor:
Here, you can see we have successfully opened the βnanoβ editor for editing Git commit messages. Add the message and press the βCtrl+Sβ button to save changes. After that, hit the βCtrl+Xβ key to close the nano editor:
Again, check the Git logs to verify if the commit message is edited or not:
We have shown you the method to edit the commit message in your preferred editor.
Conclusion
To edit the Git commit in the editor of your choice, first, open the Git local repository. Select the editor of your choice for editing the commit message using β$ git config –global core.editor < βEditor nameβ>β command. After that, edit the Git commit using the βgit commit –amendβ command in your preferred editor. This tutorial has elaborated on how to use the Git editor of choice for editing commit messages.