Failed to remove file from tracking using Git

I have a strange problem with an untracking file. I have a tracked index.css file. Then add it to .gitignore . Then I run the following and get the output:

 $ git rm --cached build/development/css/index.css rm 'build/development/css/index.css' 

Running git status gives the following:

 $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: build/development/css/index.css 

When you try to commit changes, I get the following error:

 Error:On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean during executing git commit --only -FC:\Users\dtv\AppData\Local\Temp\git-commit-msg-7154374096157077481.txt -- build/development/css/index.css 

If I try to commit changes to index.css along with external changes, the commit will go without errors. But changes to the file are still detected. What am I doing wrong?

+6
source share
3 answers

The problem is the --only option for git commit . From the git-commit manpage:

Make a fix only from the paths indicated on the command line, neglecting any content that has been supplied so far.

He tries to commit this file, apart from the previous git rm --cached .

+1
source
  • according to my observation, if we use this command git rm --cached filename , it ignores only then.
  • if you add this file to .gitignore , git will ignore this file forever. After adding the file name or path to .gitignore, we must run the following commands to track these files next time forward

    Make any incomplete code changes first, and then run the following command

    git rm -r --cached . → This removes any modified files from the index (staging area)

    git add .

    git commit -m ".gitignore is now working" → to commit changes

+1
source

You tried:

git update-index --assume-unchanged path_to_file

This will mark the file in the index, and git will stop tracking the file for any changes. In combination with adding this file to .gitignore it will stop showing it as modified when using

git status

You can also check docs for update-index

+1
source

Source: https://habr.com/ru/post/975779/


All Articles