kassie
kassie

Reputation: 757

How to ignore existing file in Git?

I need to work on file.txt locally and in Git, with different content. I want Git not to tell me that there have been changes to that file.

Is this possible?

Upvotes: 13

Views: 17562

Answers (7)

Limitless isa
Limitless isa

Reputation: 3802

SOURCETREE Terminal codes

Add ignore file:

git update-index --skip-worktree index.php

Extract ignore file:

git update-index --no-skip-worktree index.php

List ignore files:

git ls-files . --ignored --exclude-standard --others

Upvotes: 1

Tom Auger
Tom Auger

Reputation: 20101

Actually, you want --skip-worktree, not --assume-unchanged. Here's a good explanation why.

So git update-index --skip-worktree file.txt

TLDR; --assume-unchanged is for performance, for files that won't change (like SDKs); --skip-worktree is for files that exist on remote but that you want to make local (untracked) changes to.

Upvotes: 18

antonio
antonio

Reputation: 732

enter image description here enter image description here

All you need is to click the more button in sourcetree just at the right hand side of the filename, in the unstaged files section. Click ignore and make source tree perform your desired action for that file or all the files with the same type.

Upvotes: 1

janos
janos

Reputation: 124646

Maybe you want to "pretend" that the file hasn't changed when actually it did? You can do that like this:

git update-index --assume-unchanged file.txt

To undo this later:

git update-index --no-assume-unchanged file.txt

To view a list of files that are marked this way:

git ls-files -v | grep '^[a-z]'

UPDATE

As comments have pointed out, this is most probably NOT what you want to do. A better answer has been posted by @Tom Auger, use that instead.

Upvotes: 11

cellepo
cellepo

Reputation: 4479

In Eclipse Luna, this can be done [with EGit plugin I think] by doing this: right-click file -> Team -> Advanced -> Assume unchanged

Upvotes: 0

hillu
hillu

Reputation: 9611

If modifying the .gitignore file is not an option (because it is checked into git itself), consider using .git/info/exclude.

Upvotes: 2

abasterfield
abasterfield

Reputation: 2292

Can you not use .gitignore file?

Upvotes: 1

Related Questions