2

There is a file already committed.

I want to add the file .gitignore. I want to keep the file.

for example)

$ git ls-files
  foo

$ echo "foo" > .gitignore

$ echo "test" >> foo

$ git status
# On branch master
# Your branch is up to date with 'origin/master'.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   foo
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
#
no changes added to commit (use "git add" and/or "git commit -a")

As you can see, foo file status changed to "modified". I want to be not modified status. How can I add foo file to .gitignore without deleting it.


Already answered is not what I wanted. What I want is not local setting. I want method each developers not using 'git update-index --assume-unchanged path/to/file.txt'

Sunny An
  • 67
  • 6

1 Answers1

-1
  1. Remove foo from git:

    git rm --cached foo

  2. Commit your .gitignore file together with this removal:

    git add .gitignore

    git commit

xstefi
  • 471
  • 4
  • 4
  • 4
    That is not what @SunnyAn wanted... what you describe removes it completely, but it should just not track the changes anymore. – jugendhacker Apr 07 '20 at 09:59