Search code examples
gitgitignore

ignore some files in locally without change gitignore project


i am not really an expert for GIT, what I always use in git only git add, git commit -m and bla bla ( the basic ), i already get a file .gitignore from cloning the project and its already set up by team. but for running the project I have another way to add some syntax in the Makefile because I can't use the default of Makefile of that project, I have my own setting.

so here I changed the file of Makefile, but every time I want to git status that Makefile status is unstaged for commit, so i ust do manually git checkout -- Makefile, it gonna make that file back like before and not going to be add in git, for my main question is:

I want to ignore that file locally, how can I do that in command line?


Solution

  • There is no way in Git to ignore changes to tracked files.

    From the git update-index documentation:

    Users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked. This does not work as expected, since Git may still check working tree files against the index when performing certain operations. In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended.

    You'd be better off creating a file (say, Makefile.local) that you locally ignore (in .git/info/exclude) that contains something like the following:

    # Variable overrides here.
    
    -include Makefile
    
    # Other overrides here.
    

    and then run make -f Makefile.local. If the only changes you want to make are in variables (say, you want to use a different location for a program), you can just add the variables on the command line: make CC=clang.