DEV Community

Cover image for Fix your git commit messages with --amend
sharc
sharc

Posted on

Fix your git commit messages with --amend

A few words about git πŸ”§

Git is a distributed version control system, widely used for tracking changes in source code during software development.

It was created by Linus Torvalds in 2005 to support the development of the Linux kernel, with an emphasis on speed and efficiency for handling projects of any size.

Note: "distributed" means that unlike centralized version control systems (eg. SubVersion), where there's a single, central repository on a server that users check code in and out of, a distributed version control system doesn't rely on a central server to hold all the versions of a project's files. Instead, every developer has a full copy of the project repository on their local machine, including the entire history and all branches.

--amend πŸ”„

The --amend flag in Git is used with the git commit command to modify the most recent commit. This option allows you to make adjustments to the previous commit rather than creating a new one.

Suppose we have such a commit that is not well described.

Short and poorly written commit message

We can rewrite the commit message by using:

git commit --amend -m "UPDATED MESSAGE - POSSIBLY DESCRIPTIVE"
Enter fullscreen mode Exit fullscreen mode

Descriptive and well written commit message, corrected using amend flag in git

Now, our updated commit message looks like this:

git commit history previewed using git log command

Conclusion βœ”οΈ

Having such descriptive commit message we can shamelessly push it to the remote repository, knowing that the updates are unambiguous. Git is a great version control tool and has many more effective features to offer that are worth mentioning in future articles. I will be happy to come back to the topic of version control systems as it is fascinating tool for modern development and a highly worth studying subject.

Top comments (0)