Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit comment per file

I am new to git having previously used Perforce, SVN, source safe and many other source control tools.

I am looking for the functionality that I used to use in Perforce where I could construct a change list; I was able to add files to the change list and provide a comment specific to each file.

git has a staging area into which changed files are added, is there a way to provide a per file comment when adding a file to the staging area?

Or perhaps at the comment stage I can add a per file comment; I have had a good look and not been able to workout if either how to perform either - in fact from what I can seen neither is possible.

Anyone have any ideas how I could do this?

like image 643
eklektek Avatar asked Jun 12 '13 19:06

eklektek


People also ask

How do I commit each file?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

How do I comment in a .git file?

On the pull request, click Files changed. Hover over the line of code where you'd like to add a comment, and click the blue comment icon. To add a comment on multiple lines, click and drag to select the range of lines, then click the blue comment icon.

How do you commit multiple lines?

Another method of adding a multi-line Git commit message is using quotes with your message, though it depends on your shell's capacity. To do this, add single or double quotes before typing the message, keep pressing enter and writing the next line, and finally close the quote at end of the message.


2 Answers

Git does not provide such feature. The Git philosophy is to track 'content', not 'files'. Adding files to the staging area allow you to prepare precisely your commit. If several files are added to the staging area, it's because there are linked to the same feature. That's why the commit message represents the whole change.

If you need a message per file, you may consider creating several commits on a feature branch, with only one file per commit.

Hope this helps.

like image 141
Guillaume Darmont Avatar answered Oct 28 '22 02:10

Guillaume Darmont


These days you CAN add commit messages to individual files. I just did this for instance:

git commit -m 'reference containers in app' src/App.js

Context: multiple files added to git through $git add . THEN: commit message on this individual file (src/App.js).

[posting answer since this still comes up in google]

like image 14
Katinka Hesselink Avatar answered Oct 28 '22 01:10

Katinka Hesselink