Git : using .gitignore with different branches?

Git ignore tells git not to track contents of files by specific names.

Git ignore tells git not to track contents of files by specific names. Edit This only prevents git from showing files as untracked, or automatically tracking them after git add. It does not apply to files that are currently tracked.

You need to remove them manually from the branch where you wanted them ignored in the first place. IOW: git ignore does not impact existing revisions. Tracked files continue to be tracked, until you remove them Regardless of that, it is never ok to overwrite local files without warning, even when they are not (currently) tracked.

This is precisely to prevent loss of data on switching branches, of course. Many git commands accept the --force- option to just go ahead anyway, so if you know what you're doing, by all means, use that. If you are using a git workflow that doesn't allow you to use --force options, then I suggest you employ the git clean -x command to clean up untracked (i.e.

The ignored) files before doing the branch switch.

I don't want to use --force because I don't want the file to be overwritten, I want to keep the current local version... – Johanisma May 19 at 11:27 checkout does a checkout. You cannot checkout a version while keeping some files unaltered. You'd first have to make sure that the blocking files are no longer in the revision you are trying to checkout.

You can try to do the reverse: git checkout revision -- notignored1/ notignored2/ but this changes semantics: this will not update HEAD to the checkout revision, but rather overwrite the named local files while staying at the same HEAD as before. – sehe May 19 at 11:30 Added clarification to the answer – sehe May 19 at 11:33 Thanks! But the thing is : the blocking files ARE NOT in the revision I'm trying to checkout.

I basically just want to checkout all the files except those that not only are ignored, but are not in any branch (files only locally present in working tree). But I see the idea of doing the reverse...I just hope there is a more natural solution... – Johanisma May 19 at 14:12 "The following untracked working tree file would be overwritten by checkout" contradicts your assertion that these files are not in the revision you are trying to check out. I'd personally double check that (e.g. Git ls-tree -r "branchA:path/to/ignored.

File") – sehe May 19 at 14:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions