James Franco
James Franco

Reputation: 4706

Removing a directory from local Repository without affecting remote repository - Make git ignore the directory

Suppose I have the following directory structure

DirA (git Repository)
  |_DirB
  |_DirC
  |_DirD
     |_DirE
     |_DirF

I currently have my git Repository to something that looks like Above.
Everything in my repository has been pushed up.Now I would like to remove the folder DirF. I would like to remove this folder without git telling me that changes have been made and that the files of this folder do not exist.I simply want to tell git to ignore or stop tracking this folder and its contents. I have tried several things however I might be doing something wrong due to which I cant accomplish this task. Here are the two things I tried so far

Attempt:1
git update-index --assume-unchanged DirA/DirD/DirF
fatal: Unable to mark file DirD/DirF

I then tried placing a .gitignore in DirD which had DirF/ only inside it. However that does not seem to work. Any suggestions. The folder DirF is currently being tracked and has been pushed up to the repository.

Upvotes: 1

Views: 54

Answers (2)

Craig  Hicks
Craig Hicks

Reputation: 2528

I expand upon @DDoSolitary 's excellent answer.

Practically, when setting to ignore, before file deletion, the files can be iterated with find:

find ./DirD/DirF -type f -name "*" \
 -exec git update-index --assume-unchanged {} \;
 -exec rm {} \;

registered and then deleting each one.

Going back the other way, to make the files be no longer ignored, find cannot be used because the files are not their.

However, the git-update-index doc says:

To see which files have the "assume unchanged" bit set, use: (see git-ls-files[1]).

git ls-files -v  

resulting in something line

H <not ignored file including path>
h <ignored file including path>

where the letter is not important, only the case (lower for ignored, upper for not ignored).

The git-ls-files doc say:

-v Similar to -t, but use lowercase letters for files that are marked as assume unchanged (see git-update-index[1]).

So it is possible to automate the un-ignore action.

Upvotes: 1

DDoSolitary
DDoSolitary

Reputation: 327

--assume-unchaged won't work on directories, but should work on files. You should use it on all the files in DirF.

Upvotes: 1

Related Questions