13

I have been having some trouble committing a file to GitHub. I can make it to git add, but soon as I try $ git commit -m 'my message' I get an error, not allowing me to complete the process of adding a file.

$ git add HelloWorld.md

$ git commit -m 'Hello world'

I get the following answer (deleted: README.md & .DS_Store are in red):

On branch master

Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
        deleted:    README.md

Untracked files:
        .DS_Store

no changes added to commit
6
  • try with this, just to know $ git rm README.md $ git rm .DS_Store git $ commit -m "deleting files" $ git push -u origin master
    – Ethaan
    Apr 17, 2015 at 15:21
  • What does git diff -- HelloWorld.md tell you?
    – jub0bs
    Apr 17, 2015 at 15:27
  • git rm README.mdfatal: pathspec 'README.md' did not match any files
    – imasnake
    Apr 17, 2015 at 15:43
  • @Ethaan: git diff -- HelloWorld.md nothing; $ git rm README.md fatal: pathspec 'README.md' did not match any files; git rm .DS_Store fatal: pathspec '.DS_Store' did not match any files; commit -m "deleting files" -bash: commit: command not found ...
    – imasnake
    Apr 17, 2015 at 15:48
  • do you fix this problem ? Sep 20, 2016 at 22:47

4 Answers 4

10

If you changed the file but there is still nothing to commit, maybe you didn't add the file to git. (or replaced it after adding). Try adding the file before committing:

git add filename.ext

Or simply add the whole dir:

git add .
3

Apparently you did not change anything in the HelloWorld.md file (or it doesn't exist at all), so there is nothing to commit. If you just want to add an "empty" file, make sure to touch HelloWorld.md first, so the file is actually created. If it does exist, edit it (using vim HelloWorld.md for example) and make sure to save the changes in your editor when you're done.

Once you've done that and there are actual changes to the file, you should be able to commit it.

2
  • 1
    In all likelihood, HelloWorld.md does exist, because, if it doesn't exist and you run git add HelloWorld.md, you should get the following error: fatal: pathspec 'HelloWorld.md' did not match any files. That said, perhaps the OP got it and forgot to mention it in his question.
    – jub0bs
    Apr 17, 2015 at 15:24
  • The HelloWorld.md does exist. One of the main problems might be the the Your branch is up-to-date with 'origin/master' - I have not seen this message before.
    – imasnake
    Apr 17, 2015 at 15:52
1

You have nothing to commit. More specifically:

  • README.md was a tracked file, but you deleted without using git rm README.md. Git detects that the file has been deleted, but you still have to stage that deletion if you want the latter to be effective in the next commit.

  • .DS_Store is an untracked file; as such, it cannot be part of the next commit. (By the way, you should ignore such files globally.)

  • git add HelloWorld.md has no effect: the file is being tracked by Git, but there is nothing to stage in there, because you simply haven't made any changes to it since the last commit.

    How can I tell? If HelloWorld.md were a previously untracked file or if it were a tracked file which you changed since the last commit, git add HelloWorld.md would have successfully staged those changes; there would have been something to commit, and you would have been able to successfully commit.

Make some changes, stage them, and then you'll be able to commit. Finally,

Your branch is up-to-date with 'origin/master'

simply means

You haven't created any commits on master since you pushed to origin/master.

Nothing to be alarmed about.

1
  • Thank you for the info! I found a non-code solution by just deleting the whole file and starting again..
    – imasnake
    Apr 17, 2015 at 16:30
0

I added the same file again and it worked. actually the whole dir: git add .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.