Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Ignore tracked files

Tags:

git

I have some tracked files in a repository which are automatically modified when building the code. I don't want to untrack them, I just don't want them to appear as modified and I don't want them to be staged when I git add.

Is this possible?

like image 370
haymansfield Avatar asked Sep 26 '22 14:09

haymansfield


People also ask

How do I ignore a tracked file?

You can use the git clean command to remove untracked files. The -fd command removes untracked directories and the git clean -fx command removes ignored and non-ignored files. You can remove untracked files using a . gitignore file.

Is git ignore tracked?

Ignored files are tracked in a special file named . gitignore that is checked in at the root of your repository. There is no explicit git ignore command: instead the . gitignore file must be edited and committed by hand when you have new files that you wish to ignore. .


2 Answers

Another approach (from a now deleted answer by Seth Robertson, but I found it helpful so resurrecting it) is to maintain a "tracked" template file, then have local untracked version of it, ex: "config.sample.ini" or "config.ini.template" see https://gist.github.com/canton7/1423106 for a full example.

Then there won't be any concerns if the file is changed within git, etc. and you can use .gitignore (finally) on the local untracked files.

like image 10
rogerdpack Avatar answered Oct 21 '22 09:10

rogerdpack


Sure.

git update-index --assume-unchanged [<file> ...]

To undo and start tracking again:

git update-index --no-assume-unchanged [<file> ...]
like image 386
Nick Veys Avatar answered Oct 21 '22 10:10

Nick Veys