简体   繁体   中英

How to except a file/folder from versioning, but keep it in the repository in Git?

With git rm <file> a file can be deleted locally, removed from the versioning, and deleted on the repository. git rm --cached <file> does nearly the same, but keeps the file in the local working copy.

Is there possible, to remove a file/folder from the versioning (so its changes are ignored) keeping it in the repository, so that if somebody clones the repo, the file is also there, but cannot be changed with a simple add & commit ?

The short answer is no. The .gitignore facilities only prevent files from being tracked in the first place. In other words, it prevents files from entering the repository for the first time. However, once a file is tracked, it is tracked forever. All changes to that file will be tracked.

There are two general solutions. (1) Avoid adding that file to the index ever. This is just a matter of policy. (2) Place all such ignored files in an archive like UnzipMeRightAfterCloning.zip . It's an extra step for people getting into the repo, but at least the target files will never be committed.

Files already under Git you can ignore using

git update-index --assume-unchanged filename 

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

but, there also some interesting features, git - ignoring commited files and switch branch

尝试将文件/文件夹添加到.gitignore

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