automatix
automatix

Reputation: 14532

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?

Upvotes: 4

Views: 811

Answers (3)

TheBuzzSaw
TheBuzzSaw

Reputation: 8826

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.

Upvotes: 2

anber
anber

Reputation: 3665

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

Upvotes: 1

Josue
Josue

Reputation: 77

Try to add the file/folder to .gitignore

Upvotes: -1

Related Questions