HisDivineShadow
HisDivineShadow

Reputation: 1158

I want my files to remain in my git Repo but I don't want anyone to be able to change or submit changes

I have a git repo with a folder that I no longer want any changes to. I still want the folder there for history. I've tried using .gitignore but that doesn't ignore already tracked files. I tried using git update-index --assume-unchanged my-folder/ but that doesn't seem to allow for wild cards or just directory level ignoring, i.e. files modified under that folder are still showing up as modified (tried it with a * after the slash too). Any ideas on how to prevent further updates (other than rejecting PRs)?

Upvotes: 0

Views: 103

Answers (2)

torek
torek

Reputation: 489588

History, in Git, is commits. You cannot change any existing commit, not at all. You can make new commits.

Each commit has a full snapshot of every file that Git knows about. The files that Git knows about are those that are in Git's index, which Git also calls the staging area. The index is filled in from a commit when you check out that commit. (So is your working tree.) From that point on, you manipulate the index copies of each file using git add or git rm. The git add command makes the index copy match the work-tree copy, replacing whatever was there before (presumably, the copy taken from the commit).

Having manipulated the index to your satisfaction, you then run git commit, and Git packages up all the copies of every file that is in the index, into a new commit.

If you remove some files (git rm) and commit, the new commits will lack the files. The existing commits will continue to have the files, and the history, which is all the commits, is still there. You just won't see the files in your working tree, because (a) you removed them and (b) Git is checking out the new commits that don't have the files.

If you check out an old commit that does have the files, Git will copy those files to Git's index (because that's what git checkout does) and to your working tree (because that, too, is what git checkout does). If you then switch from this old commit, that does have the files, to a new commit that does not have the files, Git will remove the files from both its index (because git checkout needs to do that) and your working tree (because that's what git checkout does).

So, it's really that simple: you either have the files in new commits, or you don't.

Note that git push pushes commits, not files. You either have a commit—in which case you have all the files that are inside that commit—or you don't. Of course, some people who receive the new commits will check them out. If they had a checkout that had the files, and the new commit doesn't have the files, their git checkout (or other operation that results in a checkout, such as merging) will remove the files from their index and their working tree.

Any ideas on how to prevent further updates (other than rejecting PRs)?

Rejecting a PR that contains unwanted changes is the reason that we have PRs in the first place. Otherwise we'd just let anyone git push straight into our repositories.

Upvotes: 1

rasengan__
rasengan__

Reputation: 987

Hello @HisDivineShadow,

I've tried using .gitignore but that doesn't ignore already tracked files.

It does but you have to do some extra work ;)

To ignore an already tracked file, you need to do git rm --cached <file/path>.

Best.

Upvotes: 0

Related Questions