How do you sunset a file in git? (I mean remove a file but preserve its history.)

git

Solution

It is indeed `git rm`.

Of course it preserves the files history. It is in the prior commits and so you can rest, assured that it is there.

And yes, you can `git rm` files that you did just delete, the only difficulty is likely that you can't tab complete the file names, as they don't exist.

When working in a `git` repository it easier if you can remember to do `git rm <file>` instead of doing the `rm <file>` and then `git rm <file>`.

As `git`, by its very purpose, "preserves the files history in the repository" it is more likely to see a comment when this behavior isn't happening. A warning note that says the opposite of the design, such as "Warning, this function does not preserve history in the repository", is more likely than stating that an option of `git` does preserve file history.

Problem

I have a git project. Some source files have been dispensed with in the latest version. I want to remove them from the repo from now forward, but preserve their history thus far. I.e. If I check out yesterday's repo it had better have these files or it wouldn't compile. I know it's probably "git rm", but I have 2 problems with git rm right now. One is that I can't find any documentation that definitively says "git rm preserves the file's history in the repo". And I've already deleted these files from my working directory, so I doubt I can git rm files that aren't even there. (I could copy them back, just to be able to do a git rm, but I want to make sure I'm doing things the right.)

Original source

Related problems