Git

How to Use the Editor of My Choice For Editing Commit Messages in Git?

The Git commit is an essential component of the Git project, which saves all tracked changes into local Git repositories so that they can later be accessed by remote repositories. To better understand this concept, most developers like to commit messages along with changes while working on the same project. As a result, the commit message makes it simple for developers to understand what other members did.

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:

$ cd "C:\Git\Test"

Step 3: Generate New File
Utilize the β€œtouch” command to generate a new file:

$ touch Demofile.txt

Step 4: Add Untracked Changes to Tracking Index
After that, add the untracked file to the tracking index by executing the below command:

$ git add Demofile.txt

Check out the β€œgit status” command to verify if the changes are added to the tracking index or not:

$ git status

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:

$ git commit --amend

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:

$ git log

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:

$ git config --global core.editor "nano"

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:

$ git commit --amend

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:

$ git log

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.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.