0

I have problem with git like

E235 attention

When I do git commit. Then I tried git commit -m, it said to me that error: switch 'm' requires a value

I am very confused with this, could you please give me some ideas?

D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38
anhbuiask
  • 63
  • 1
  • 2
  • 8
  • 2
    git needs a commit message when using with -m parameter... like `git commit -m "commit message"` – Lino Jan 11 '20 at 14:48
  • 2
    In the future, please [do not post images of text](https://benknoble.github.io/blog/2019/11/24/pics-text/) – D. Ben Knoble Jan 11 '20 at 15:27
  • 2
    @ARK 1) Questions are downvoted, not users. 2) Zero due diligence or effort as explained in the FAQ. 3) Trivially researchable. This is a fine example of a question that could be downvoted along with rationale. – Dave Newton Jan 11 '20 at 15:27
  • @DaveNewton I see. – ARK Jan 11 '20 at 15:30

3 Answers3

6

-m switch indicates that you will add a commit message (commit name). When you enter -m it means you will enter a string after it like:

  git commit -m "This is my first commit -  I changed xy class in it"

Moreover,

 git commit -a -m "add button to signup flow"

is equal to:

  git add .
  git commit -m "add button to signup flow"

Notes:

  • This is not exactly a rails question, it is a git question.
  • It is conventional to name your commit messages in present tense i.e. do this, do that etc.
  • Original issue is not exactly what you posted as a title to your question. It is two-pronged: vim, git. Nothing to do with rails or heroku.
ARK
  • 772
  • 7
  • 21
  • 1
    **Important Note:** If you have added a new file then instead of `git commit -a -m "commit message"` or `git commit -am "commit message"`, use `git add . && git commit -m "commit message"` or new files won't be added to the commit. – ARK Jul 05 '21 at 12:18
1

The message in the link indicates that at some earlier, you started writing a commit message and did not close the file (or perhaps it is open in a different terminal window). You could usually just delete the swp file, unless you want to recover its contents. See here and here for further details.

git commit -m expects that a commit message will follow the -m flag, which is what gives your second error. You can do:

git commit -m "some commit message"

to complete the commit.

GoodDeeds
  • 7,956
  • 5
  • 34
  • 61
1

There are several things going on here.

  1. OP tries to commit the usual way. Vim, the editor in the screenshot, gives an error because of the swap file existing. This usually indicates one of
    1. Vim is open somewhere editing that file; or,
    2. Vim crashed (or was killed) while editing that file.

This can be especially confusing for new vim users. This is, however, a vim error and not a git error. For commit messages, the solution is usually best to

  1. Quit vim (:q!)
  2. Delete the swap file
  3. Try to commit again (and use :wq or ZZ or any of the other ways to exit vim properly). If you don’t like vim, configure git to use another editor. (These last two statements have highly upvoted SO questions, if you google.)

NOTE I do not necessarily recommend off-hand deletion of swap files any time there is an issue.

  1. Next, though, the OP seems to have abandoned vim (a normal thing for newer users, though I would encourage the OP to run vimtutor and at least try vim out ;) ). Probably thinking -m would use their already typed message, they tried it. However, according to git help commit, -m requires the message as an argument to the command.

I do not recommend the -m form generally, as one line is not enough for most git commits.

D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38