2

In my Laravel 5 project in root dir there is a file .gitignore, which has rules:

/node_modules

/public/client_secret.json
/public/.htaccess

but running

git add . 

command I see that 2 files above are in git modifications, but I expected they would be ignored. Proposed url has a lot of options, I am not sure which is valid for me.

Which is right way?

rid_mankon
  • 31
  • 1
  • 4

2 Answers2

3
  1. Save your local and server files you want to exclude from git
  2. Run at your local (in root of your app):

    git rm --cached public/.htaccess
    git rm --cached public/client_secret.json
    
  3. After pushing these files would be removed, restore them mannually

  4. These files would be excluded from git
Just Shadow
  • 10,860
  • 6
  • 57
  • 75
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
1

.gitignore only ignores untracked files.

Since these files show up as modified (not new) that means they are already being tracked, so you can't ignore them.

Some people will tell you tricks using index flags; this is not how they are meant to be used, and using them in that way will likely cause other problems.

If the files are not meant to be in the repo, you could remove them from the index and commit the removal. This can be a bit risky, because git will think that part of what it should do when moving from an older commit to the now-current one is to delete the file from the working folder. You could avoid that by editing history to look like the files were never checked in, but that requires coordinating a history rewrite with your team. (You would use filter-branch most likely; you can search SO for existing Q&A that document this procedure thoroughly if you want more information.)

If the files are meant to be there, and you simply don't want to record when they change (because they contain local changes), then what I would do depends on the project's build tooling. Generally I would set things up so that I didn't need to store the modified files in the work tree (or at least not in the checked-in copies of the filles). Again I woudl search for existing Q&A that cover this topic in detail.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52