Joy
Joy

Reputation: 4463

git status showing deleted files even after doing updating git index

I have cloned a git repo. During building, a lot of files in certain folder is showing to be deleted while doing: git status.

They are already in remote repo which I don't want to delete. Regarding this, I have gone through following post: Git ignore deleted files

After that I put the directory in .gitignore as well. Still while doing git status, I can see the same.

Upvotes: 1

Views: 1785

Answers (2)

tmaj
tmaj

Reputation: 34947

Having files deleted locally and not deleted in remote

This will not work long term. When someone else clones your repo they will get the files.

Restoring local files

>git checkout . will restore the deleted files.

/mnt/c/git/repo666 (branchX)>git status
On branch branchX
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    a.txt

no changes added to commit (use "git add" and/or "git commit -a")
/mnt/c/git/repo666 (branchX)>git checkout .
/mnt/c/git/repo666 (branchX)>git status
On branch branchX
nothing to commit, working tree clean
/mnt/c/git/repo666 (branchX)>

Upvotes: 1

Venkataraman R
Venkataraman R

Reputation: 12959

If you are still seeing them in the git status, it could be due to cache.

  1. Remove all files from cache, using the below command

    git rm -r --cached .

  2. If you want the ignoring to happen across repositories -> update gitignore

    Post update, add files individually as per your commit

    git add .

  3. If you want the ignoring to happen only local repository and not at the repository level, update the exclude file: $GIT_DIR/info/exclude, instead of git ignore

    Post update, add files individually as per your commit

    git add .

Read more on ignoring files in GIT

Upvotes: 1

Related Questions