Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore new changes to a tracked file with git? [duplicate]

When I run git status:

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   .gitignore
#       modified:   .project
#       modified:   reports/images/2014-03.png
#       modified:   reports/images/graph-2014-03.bmp
#       deleted:    reports/phpbmp/cache/0/02/027/0270/phpThumb_cache_portal.gep.co.za_src02707010e1e50bc80594
f31460d514c4_par80d8993b181666aca11d7be02b12fea7_dat1399293161.bmp
#       deleted:    reports/phpbmp/cache/0/02/027/0270/phpThumb_cache_portal.gep.co.za_src02707010e1e50bc80594
f31460d514c4_par80d8993b181666aca11d7be02b12fea7_dat1399293182.bmp
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       README.MD
#       reports/phpbmp/cache/9/
no changes added to commit (use "git add" and/or "git commit -a")

I realised that I don't want changes to the following files be tracked:

.project
reports/images/*.png
reports/images/*.bmp
reports/phpbmp/cache/*

So I added these files to .gitignore

How do I remove the files from the current working directory under Changes not staged for commit?

like image 355
tread Avatar asked May 15 '14 08:05

tread


People also ask

How do I Gitignore an already tracked file?

Simply move the files to a folder outside of git, then do "git add .", "git commit". (This removed the files) then add the gitignore, referencing the files/folders, commit again to add the gitignore file to git, then copy/move back in the folders, and they should be ignored.

How do I force Git to ignore a file?

You can create a .gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the .gitignore file in to your repository.

Which Git command is used to ignore the files which are not tracked?

A . gitignore file is a plain text file that contains a list of all the specified files and folders from the project that Git should ignore and not track. Inside . gitignore , you can tell Git to ignore only a single file or a single folder by mentioning the name or pattern of that specific file or folder.

How do I Untrack a Git file without deleting it?

Using the git rm –cached Command However, the git rm command provides the –cached option to allow us only to remove files from the repository's index and keep the local file untouched. As we can see, the user-list. txt is “deleted“. Further, since its local copy is still there, it has been marked as “untracked”.

Should Git ignore be tracked?

Yes, you can track the . gitignore file, but you do not have to. The main reason of having this file into repository is to have everyone working on the project, ignoring same files and folders.


1 Answers

If I understand well you want filename to be in the git repository. However you don't want to be notified of new changes to filename. You can do this using this command:

git update-index --assume-unchanged <filename>

If you wanna start tracking changes again run the following command:

git update-index --no-assume-unchanged <filename>

additional info: editing .gitignore will only ignore files so they will not be added to the git repository. However files that are tracked already will not be ignored.

like image 178
Chris Maes Avatar answered Sep 18 '22 12:09

Chris Maes