How to ignore existing, committed files in git? [duplicate]
Asked Answered
M

3

6

Possible Duplicate:
GIT: Ignoring Version-Controlled Files

There are plenty of answers around .gitignore on Stackoverflow, still I haven't found an answer:

I have an existing git project, with a readme.md and a sample_folder/, both on top-level. I do want to remove these from my git(hub) repository in general. But I would like to ignore them, that is, preventing them to be pulled at all, in a certain cloned local repository, i.e. on a deployment machine.

.gitignore I understand, is only about ignoring non-committed files? Frankly, I don't find anything around hiding (from pull+commit) stuff that already is committed...

In the days of Perforce I would simple exclude it from the respective 'client spec' (which is pretty close to a locally cloned repo):

//whatever/myProject
-//whatever/myProject/readme.md
-//whatever/myProject/sample_folder

Sure, I could settle for a second branch where I simply delete readme and the entire sample folder. But then, I would have to keep merging over every tiny fix from 'develop'. Which is something, I would rather avoid... I'd rather prefer a local 'exception' over a (tracked) branch.

Also, I think git rm --cached whenever I do commits (which may also happen now and then from my 'deployment repo')...

Mathematics answered 16/7, 2012 at 16:23 Comment(3)
it''s difficult to understand your problem... why would you want to have files ignoring pulls? I can imagine the source of trouble, since not all repos would then be at the same state while at the same commitBacktrack
Well, for any intersted/developer person it's helpful to have i.e. a sample_folder (or a docs-folder or a readme), in a deployment scenario any of this is superficious, perhaps even problematic...Mathematics
@Wooble: This sounds very promising! Thanks heaps. Will investigate.Mathematics
L
5

Perhaps I got the question wrong, but wouldn't the following solve your problem?

git rm --cached readme.md sample_folder/*
echo "readme.md" >>.gitignore
echo "sample_folder/*" >>.gitignore
git commit -am "Untracked some files"
Lendlease answered 16/7, 2012 at 18:32 Comment(0)
C
2

It sounds like you might be using a git checkout as your deployment method. Sometimes this works, sometimes it needs a little more. If there's development artifacts in the repository, you need a little more.

The most obvious way to deal with this is to have a deployment script that does the pull and then deletes the superfluous directories and files. This unfortunately leaves you with a partial repository that might confuse people and it adds a special script that has to remember to be used and kept up to date.

Another way to handle it is to have a deployment branch. Make a branch, delete the offending files and directories, and then pull from that branch. Yes, you'd have to merge changes from your development branch into deployment. You see this as a chore, but it is a safeguard. If you are rapidly making chances in development and just as rapidly deploying them, you might have a problem with your deployment cycle.

You want a step between development and deployment in which you can consider and test your changes. If nothing else, this prevents developer A from pushing a bad change and admin B compounding the mistake by unknowingly pulling it into production. You also want to be able to push to development and share your work with other developers without ALSO risking it being pushed into production.

You might be the single person handling development AND deployment right now, but you may not be later. If nothing else, this protects yourself from accidentally pushing an unstable change to development and then compounding that mistake by pulling it into deployment before you have a chance to think.

Confiture answered 16/7, 2012 at 18:20 Comment(1)
For serious release I'd certainly have a 'stable' branch, of course. But for my quick and dirty 'deployment' I am very effort-averse :) And I want to push tiny fixes back (without seeing many bogus changes, i.e. all those deletion, even if I won't add those to stage). I will investigate Wooble's comment above...Mathematics
N
0

This not an issue about .gitignore. If these are not code, you should track it in a separate repo via submodules and simply don't run any git submodule commandsh on the server. Or just script the removal of these on the deployment machine after a checkout.

Niu answered 16/7, 2012 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.