SOFe
SOFe

Reputation: 8224

Ignore line in .gitignore

The .gitignore of a project (maintained by someone else) is like this:

.idea/*
!.idea/watcherTasks.xml

I want to add private watcher tasks, so my watcherTasks.xml is changed. But I don't want to commit it.

I don't want to type git reset .idea/watcherTasks.xml (or specify the paths) every time I git add/git commit. So I tried to use .git/info/exclude to ignore the file locally:

.idea/watcherTasks.xml

However, the .git/info/exclude line cannot override the .gitignore line (probably because ! has higher priority).

Is there something I can put in .git/info/exclude to cancel the effect of the !.idea/watcherTasks.xml line in .gitignore? I don't want to modify the .gitignore since I do not maintain the project.

This question does not ask for approaches like git commit $path, because I do not want to change future commit commands to use.

Upvotes: 2

Views: 333

Answers (3)

Danny Carlton
Danny Carlton

Reputation: 51

I tested this using # and it worked.

Before...

public_html/includes/local.php

local.php is ignored, but when I changed it to...

#public_html/includes/local.php

local.php is there.

I can see no error warnings on my github desktop, nor on the site itself.

Upvotes: 1

VonC
VonC

Reputation: 1329672

If your .idea/watcherTasks.xml is already tracked, you can:

  • modify it locally
  • make sure it remains not added/committed with

    cd /root/folder/of/your/local/repository
    git update-index --skip-worktree -- .idea/watcherTasks.xml
    

That means:

  • no need to override an ignore rule
  • no need to modify a .gitignore

Your tracked file remains tracked, but none of your local modification will be added or committed.

Upvotes: 1

Bill Sawyer
Bill Sawyer

Reputation: 31

If I understand what you are asking (summarized: to ignore an ignore rule), the answer is No. In the .gitignore documentation: https://git-scm.com/docs/gitignore it clearly states the following:

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected;

Now, as you note, you do not want to affect the overall repository. So, I think you are out of luck on this. Sorry.

Upvotes: 2

Related Questions