Laura
Laura

Reputation: 3383

Git does not add files (nothing to commit)

I tried to clean my git up a bit, so I untracked all files with

git rm -r --cached .

Afterwards, I tried to add them again with

git add -A

or

git add .

but, neither of them seem to work, because when I try to commit, it says that there's nothing to commit and the working directory is empty. I've run those in the root folder, so that should not be the problem. Any ideas?

Upvotes: 1

Views: 1196

Answers (3)

mvp
mvp

Reputation: 116407

If you simply want to return state of your repository to original situation (before git rm), do this:

git reset       # unstage - undo effect of "git add" or "git rm"
git checkout .  # revert any local changes

Note that git rm followed by git commit would not decrease space used by deleted files, so this is not really good way to "clean up".

Instead, you could have simply started from scratch:

rm -rf .        # remove everything, including .git directory
git init        # initialize git repository from scratch

Upvotes: 0

linuxnewbee
linuxnewbee

Reputation: 1008

you can track again by setting --no-assume-unchaged flag. Try with this command:

git update-index --no-assume-unchanged filename

Upvotes: 1

Gabriel Petrovay
Gabriel Petrovay

Reputation: 21944

If after the

git rm -r --cached .

you do not commit, nothing changes in the repo history. That is why the add commands have no effect. (After a rm, you do a git reset HEAD ...files... or git checkout ...files... to undo the effects of git rm, not with git add)

Do this:

git rm -r --cached .
git commit -m "Untracked everything"

Now git add will work:

git add -A

or

git add .

Upvotes: 2

Related Questions