1

I'm keep getting Changes to be committed message from git status command even after committed and pushed to origin. I can see the changes on origin/master. How can I get rid of this message?

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:  foo.php

$ git commit -m 'message' foo.php
On branch master
Your branch is up to date with 'origin/master'.

nothing added to commit

EDIT

Actually, foo.php was a different name say foo-org.php before and I renamed it with:

git mv foo-org.php foo.php

I run git add foo.php then git commit -m 'renamed' foo.php then git push orign master. I can see the file on online repo (origin/master) is up to date, so I have no idea why it is still saying "Changes to be committed".

ASH
  • 459
  • 5
  • 18
  • 4
    You must add your changed file with `git add`. Then you can commit this change. I recommend you to take a look at this [guide](https://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide). – flaxel Jan 08 '21 at 09:48
  • I did git add before commit. The file is on master already as mentioned in my post. I tried to add again just in case, but nothing happened. – ASH Jan 08 '21 at 09:55
  • you don't "get rid of a message" because you don't like it. You read the message, understand that `foo.php` is modified and not committed, reason on why that is the case, and take the appropriate course of action. If you run `, could you post the entire commands you run? – Daemon Painter Jan 08 '21 at 09:56
  • It seems you didn't understand quite well how Git works. Take your time and read the [Git book](https://git-scm.com/book/en/v2). You will see your question from a different angle after that. – axiac Jan 08 '21 at 11:55
  • I run 'git status' 'git add' 'git commit -m' 'git push origin'. Those commands have been working OK till I get this situation today. I run those commands quite few times on foo.php already, but 'git status' still shows the Changes to be committed' message. – ASH Jan 08 '21 at 12:12
  • What does `git diff foo.php` tell you ? – LeGEC Jan 08 '21 at 13:56
  • Do you have a pre-commit hook installed? If so, what does it do? – torek Jan 09 '21 at 00:32

1 Answers1

0

Since the remote master branch is up-to-date, try and reset your local branch to it:

git fetch
git switch -C master origin/master

Or, if you are already locally on master:

git reset --hard origin/master

Check then if the git status still report a non-empty index.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250