1

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.

Joy
  • 4,197
  • 14
  • 61
  • 131

2 Answers2

1

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)>
tymtam
  • 31,798
  • 8
  • 86
  • 126
  • Hi @tymtam, but I don't want to restore the deleted files. I deleted them in my local. I just don't want them to get deleted in the remote. I want to ignore them from git. – Joy Nov 05 '19 at 06:18
  • Having a different setup in local and remote seems wrong. What should happen if someone clones you repo? They will get the files, is that desirable? – tymtam Nov 05 '19 at 06:41
1

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

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58