How to ignore existing file in Git?

前端 未结 7 501
南笙
南笙 2021-02-05 19:31

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

相关标签:
7条回答
  • 2021-02-05 20:09

    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.

    0 讨论(0)
  • 2021-02-05 20:11

    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.

    0 讨论(0)
  • 2021-02-05 20:13

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

    0 讨论(0)
  • 2021-02-05 20:13

    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
    
    0 讨论(0)
  • 2021-02-05 20:18

    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.

    0 讨论(0)
  • 2021-02-05 20:26

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

    0 讨论(0)
提交回复
热议问题