4

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?

automatix
  • 14,018
  • 26
  • 105
  • 230

3 Answers3

2

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.

TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58
0

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

Community
  • 1
  • 1
anber
  • 3,463
  • 6
  • 39
  • 68
  • 1
    It is important to note that you will have to do that command after every `add` and before the `commit`. – nwalke Apr 03 '13 at 15:27
  • This works, but it is extremely unfriendly toward any workflow that involves the use of `git add --all`. – TheBuzzSaw Apr 03 '13 at 15:31
-1

Try to add the file/folder to .gitignore

Josue
  • 77
  • 7
  • I've added the file to .gitignore, but it still appears in the `git status` file list, when I edit it. – automatix Apr 03 '13 at 10:38
  • I´m not sure why this happends. In my case, I have several files added to .gitignore and when I make a new commit, this files are not shown in the stash. Have you made commit after modifying .gitignore file?Maybe this is the cause – Josue Apr 03 '13 at 12:36
  • In my case the file is already being versioned. `.gitignore` works only for the files/folders, that have not yet added to / already been removed from the versioning. – automatix Apr 03 '13 at 12:44
  • What about untrack the file?? Look at this: http://stackoverflow.com/questions/6964297/untrack-files-from-git – Josue Apr 03 '13 at 15:17
  • -1 This does not do what the question is asking for. Because it cannot be done. – nwalke Apr 03 '13 at 15:25