How to ignore existing file in Git?

前端 未结 7 512
南笙
南笙 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: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.

提交回复
热议问题