1

That's my first question on StackOverflow, so every advice will be very appreciated.

I'm working with PhpStorm as IDE, and my partners and I are we using GitHub as a Version Control System.

Every time you make a commit change (like a push) Git allows you to add a comment on the files that you change.

And we arrive to the problem

As you can see on this image I have changed 3 files (1 php class file, and 2 twig templates):

img

The problem is that I want to add a commit message for every different file, but the commit message box only allows you to comment every file with the same comment.

The only way to do that is committing every file separately, but I want a faster way.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Lotan
  • 4,078
  • 1
  • 12
  • 30
  • Can't you just remove the ticks from checkboxes ? (not a phpstorm user, just guessing .. which is why this not an "answer") – tereško May 13 '17 at 17:10
  • you are committing a change, if the change affect multiple files then you should reflect that in your comment. – meda May 13 '17 at 17:13
  • @meda that would be very limiting view on version control. Besides, he does not want to commit all the three changes, because each of those files was probably changed because of a different reason. – tereško May 13 '17 at 17:17
  • You're not committing files, you're committing snapshots of your entire worktree, so when git forces you to write 1 commit message for all the files you're committing this is not just to be obtuse, but 1 commit equals 1 commit message. If that commit contains 1000 files, that commit will still have 1 commit message. If you want to have 1 commit message per file you will have to make 1 commit per file as well. You want a faster way, but really... **why**? Why do you want to commit each file separately? – Lasse V. Karlsen May 13 '17 at 17:40
  • @LasseV.Karlsen I express myself wrong, or you don't understand me. I don't want to commit each file separately , i wan't to add a different commit-message to each file. Cause the changes on every file could be different. – Lotan May 13 '17 at 18:17
  • Then you simply write: `file1: Change A, file2: Change B: file3: Change C`, and so on. I'm pretty sure that's not what you want, but that's all you can do. – Lasse V. Karlsen May 13 '17 at 18:27
  • @LasseV.Karlsen that's exactly what I'm doing, but seems dirty for me – Lotan May 13 '17 at 18:29
  • 1
    Yes, you're right, it **does** seem dirty, but that is because you're lumping together unrelated changes. **That** is the dirty part. If you fixed bug X, that's what your commit message should say, the number of files attached to the commit is a detail about your fix. If, on the other hand, your one commit contains 1 unrelated change per file, then you're basically not using source control right. Fix one thing at a time, commit, rinse, repeat. – Lasse V. Karlsen May 13 '17 at 18:38

2 Answers2

3

Git does not allow creating different commit messages for each file in a commit. See e.g. this thread or this

So you need to commit each file separately if you wat a different message.

Community
  • 1
  • 1
Dmitrii Smirnov
  • 7,073
  • 1
  • 19
  • 29
  • I see: "The Git philosophy is to track 'content', not 'files". thanks for the links Dmitriy – Lotan May 13 '17 at 18:22
1

There is no faster way in PhpStorm. The commit message is about the change you're committing, which is not file-specific. If you want to have a different commit message per file, you need to split them over multiple commits. The only potential way to do it faster, is to not use PhpStorm but to do it from the command line (assuming you have git installed).

First run git status to make sure nothing is staged for commit yet. If there is, run git reset HEAD path\to\file to unstage the files.

Then, per file, you can add them (one file at a time, one folder at a time, or whatever's left) and commit with a message. Note: I use a Linux machine for development and have never tried running git from the Windows command prompt, but I assume the commands are the same on Windows:

git add src\Controller\UserController.php
git commit -m "Commit message for UserController.php"

git add src\View\templates
git commit -m "Commit message for home.twig and publicProfile.twig"

git add .
git commit -m "Commit message for remaining files, like in web\assets\js"

git push

git push should push those 3 commits to Github for you.

rickdenhaan
  • 10,857
  • 28
  • 37