简体   繁体   中英

Ignore file removed from local git repo that should stay in other repos

I git cloned an arduino sketch that requires me to remove the libraries directory and place it elsewhere outside the repo via mv ./libraries $sketchdir/sketch_libraries/ . I can't compile the sketch with the directory present so I deleted it; however, when I run git status it complains about the missing contents of the libraries directory.

I'd like to tell git to ignore the fact that this directory is missing on purpose and stop pestering me. I tried adding libraries/* to .gitignore, but that failed to give me the desired results.

How can I accomplish this?

If you want to ignore that directory only on a specific host, try adding the directory path to the .git/info/exclude instead of .gitignore :

Your exclude file should look like this:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
libraries/*

git status won't even complain that the exclude file has changed.

I just figured out what's the issue here. By adding the directory to the .gitignore or the info/exclude, git wont track that directory if it's local. But in this case, you want to remove it locally and keep it on the remote repo, and want git to untrack that remote directory.

To do so, you just run this command:

git update-index --skip-worktree libraries/*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM