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.