In the first line of a git commit message I have a habit of mentioning the file that modified if a change doesn't span multiple files, for example:
Add [somefunc] to [somefile]
Is this a good thing to do or is it unnecessary?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityVersion control tools are powerful enough to let the person see what files were modified, and what methods were added. It means that in general, log messages which plainly duplicate what already exists are polluting the log.
You added somefunc
method to fulfill a requirement, i.e.:
This means that your log messages must rather explain what features/bugs were affected or what was the purpose of the refactoring.
No. There are plenty of ways to examine the contents of a commit. The comment should describe the purpose of the commit.
if a change *doesn't* span multiple files
. So you suggest to not include the filename, ever? Not even if the commit is specific to the file only – say, a syntax error bugfix? I feel this answer is too narrowly considered, as that would make e.g. git log
pretty much illegible
Don't forget to add TICKET/ISSUE NUMBER .
If you have any feature or issue tracking system with a ticket # or issue #, be sure to put that ID # in the commit. That will help anyone who wants to know more about the feature or issue that you were working on.
In my last project, there was a macro which was developed to make sure that the first 7 digits of the comment was a valid issue number from clear quest (our issue/feature tracking system).
I want to add a different perspective here.
My Answer is Yes Or No. But Generally I would say Yes.
Version control is indeed powerful enough to know which file is being updated. But, when we do
$ git log
We only see the commit message. That what most people do.
By looking into the log itself. It adds additional context to it. For example:
readme.md: Fix typo detected by language tool
Is better than
Fix typo detected by language tool
However, if the changes spawn multiple files, then at least mention the component that is being edited.
API: Fix reset password not sent email to user
By reading it, we know that the error being fixed is at the API component, and it probably under API directory at the code base.
We could however do
$ git show COMMIT_ID --name-only
but it adds more step just to get the files.
I do that type of thing when I'm committing e.g. the fix for a defect that required changes to multiple files. This makes it a bit easier to tell what actually changed without looking at individual files in the changeset.
For single file changesets, this is unnecessary.
The first line is always a high-level description of the changeset, like a link to the defect or user story.
If it's relevant information in the narrative of the commit message, then yes, include it. If the only bit of information is the filename itself, then no.
For example this make sense: "Moved the build_foo() function from fooutil.c to foobase.c, since most programs that want to use build_foo() are already including foobase.c"
This one doesn't: "Updated the build_foo() in fooutil.c to take a bar parameter."
If you can include the verb that the file is representative of for e.g slideDesigner: fixed funcX(), returns obj
instead of the actual fileName (e.g slide-designer.vue
or main-slide-designer
) its much better.
In the end there is no hard/fast rule you should follow, it's boils down to what you are comfortable and confident with. IMHO, if I include the term slideDesigner
rather than just fixed funcX(), returns obj
it makes the commit history more usable to me and I am more likely to further research the actual files in that commit for I know beforeHand of a context (slideDesigner) for my mind to constructively relate to the problem I am currently dealing with.
Thanks.
The only time I could see this being useful for a single file checkin is if you've made changes to a function used in many places within the file with the result that the diff is cluttered. Even then I'd put the change tracker # and a plain text description of the change first.
Look at how easy or difficult it is to figure out which files a commit modified and/or how easy it is to figure out the list of commits modifying a file. Then base your decision on your findings. Your setup may be different from mine.
(For example, the Xcode editor has a “history” button which shows two versions side by side with a diff, and you can pick commits for either side. Pointless to have the file mentioned in the commit message. Unless the change is something like “fix outdated comments xyz.cpp”. )
I think the real question here is how limited in scope are your commits? If you wait to commit a variety of unrelated changes together in one commit, then you might feel the need to specify what files were changed for what purpose.
However, if you simply made more narrow commits more frequently, then a single commit would explain which files were modified and you could simply describe what the purpose was in the message.
More commits, more often. That's the way you can avoid being so verbose in your messages.
It shouldn't
Everybody who is interested can see changes in a history
It's also not feasible in larger systems as many files might be auto generated